- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的测试中有以下几行(使用 react 和 enzyme ):
const input = mount(<MyComponent/>).find('input').node;
input.focus();
input.select();
我已将 enzyme 从 v2 升级到 v3,现在它抛出以下错误:
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.
但是,当我使用 getElement()
就像错误中建议的那样:
const input = mount(<MyComponent/>).find('input').getElement();
生成的对象没有原始 .node
中的功能:
TypeError: (0 , _enzyme.mount)(...).find(...).getElement(...).focus is not a function
TypeError: (0 , _enzyme.mount)(...).find(...).getElement(...).select is not a function
我应该用什么代替 .node
和 .getElement()
使此代码在 enzyme 3 中起作用?
最佳答案
您应该使用 .instance()
或 .getDOMNode()
而不是 .node
,这取决于您是否将结果用作 ReactElement或 DOMComponent。
关于javascript - 错误 : "Attempted to access ReactWrapper::node, which was previously a private property" when using enzyme 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48204668/
使用玩笑和 enzyme 在 react 中编写单元测试。在检查组件状态时,它会抛出错误“ReactWrapper::state() 只能在类组件上调用”。 import React from 're
将 React 元素传递给“mount”函数时遇到此错误: it("Book - move book to a shelf should work", () => { let test = (
我正在为连接到 Redux 的 React 组件编写单元测试。该组件的功能之一是如果 questionReducer.showquestions == true 则显示数据。我尝试通过使用 wrapp
我的测试中有以下几行(使用 react 和 enzyme ): const input = mount().find('input').node; input.focus(); input.selec
我是一名优秀的程序员,十分优秀!