所以我尝试使用 jest 和 enzyme 测试一些基于 material-ui 切换组件的功能。
我有一个通用的 clickIt 函数,它适用于其他 material-ui 组件,但在这个组件中它似乎没有触发状态更改
function clickIt(wrapper, selector) {
let elem = wrapper;
if (selector) {
elem = wrapper.find(selector);
}
const node = ReactDOM.findDOMNode(elem.node);
TestUtils.Simulate.touchTap(node);
}
在测试中:
const toggle = wrapper.find('#subscribe-toggle');
expect(toggle.props().checked).to.be(true);
clickIt(toggle);
expect(toggle.props().checked).to.be(true); // <- fails
关于如何解决这个问题有什么想法吗?
最佳答案
通过使用:
// clickIt(toggle);
// toggle.last().simulate('click');
toggle.props().onChange(); // None of the above work, you can thank material ui for that one
关于javascript - 模拟点击material-ui切换组件测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42854223/