最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: "Attempted to access ReactWrapper::node, which was previously a private property" when usi

programmeradmin0浏览0评论

I have the following lines in my test (using react and enzyme):

const input = mount(<MyComponent/>).find('input').node;
input.focus();
input.select();

I have upgraded enzyme from v2 to v3, and now it throws the following error:

Attempted to access ReactWrapper::node, which was previously a private property on Enzyme ReactWrapper instances, but is no longer and should not be relied upon. Consider using the getElement() method instead.

However, when I use getElement() like suggested in the error, like so:

const input = mount(<MyComponent/>).find('input').getElement();

The resulting object doesn't have the functions that were in the original .node:

TypeError: (0 , _enzyme.mount)(...).find(...).getElement(...).focus is not a function

TypeError: (0 , _enzyme.mount)(...).find(...).getElement(...).select is not a function

What should I use instead of .node and .getElement() to make this code work in enzyme 3?

I have the following lines in my test (using react and enzyme):

const input = mount(<MyComponent/>).find('input').node;
input.focus();
input.select();

I have upgraded enzyme from v2 to v3, and now it throws the following error:

Attempted to access ReactWrapper::node, which was previously a private property on Enzyme ReactWrapper instances, but is no longer and should not be relied upon. Consider using the getElement() method instead.

However, when I use getElement() like suggested in the error, like so:

const input = mount(<MyComponent/>).find('input').getElement();

The resulting object doesn't have the functions that were in the original .node:

TypeError: (0 , _enzyme.mount)(...).find(...).getElement(...).focus is not a function

TypeError: (0 , _enzyme.mount)(...).find(...).getElement(...).select is not a function

What should I use instead of .node and .getElement() to make this code work in enzyme 3?

Share asked Jan 11, 2018 at 10:20 Eran ShabiEran Shabi 15.1k8 gold badges33 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Instead of .node you should use .instance() or .getDOMNode(), depends if you used the result as a ReactElement or DOMComponent.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论