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

I have the following lines in my test (using react and enzyme):const input = mount(<MyComponent>

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745060404a4608931.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信