So I'm trying to test some functionality that is based on the material-ui toggle component, using jest and enzyme.
I have a generic clickIt function that works well for other material-ui components, but in this one it doesn't seem to be triggering the state change
function clickIt(wrapper, selector) {
let elem = wrapper;
if (selector) {
elem = wrapper.find(selector);
}
const node = ReactDOM.findDOMNode(elem.node);
TestUtils.Simulate.touchTap(node);
}
And on the test:
const toggle = wrapper.find('#subscribe-toggle');
expect(toggle.props().checked).to.be(true);
clickIt(toggle);
expect(toggle.props().checked).to.be(true); // <- fails
Any idea on how to solve this?
got around it by using:
// clickIt(toggle);
// toggle.last().simulate('click');
toggle.props().onChange(); // None of the above work, you can thank material ui for that one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With