So I'm trying to test some functionality that is based on the material-ui toggle ponent, using jest and enzyme.
I have a generic clickIt function that works well for other material-ui ponents, 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?
So I'm trying to test some functionality that is based on the material-ui toggle ponent, using jest and enzyme.
I have a generic clickIt function that works well for other material-ui ponents, 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?
Share Improve this question asked Mar 17, 2017 at 9:51 Oscar FrancoOscar Franco 6,2606 gold badges37 silver badges70 bronze badges 3-
The toggle ponent doesn't have a a
onTouchTap
attribute, only aonToggle
attribute. It could be that thetouchTap
event is therefore not triggering it? – Aron Commented Mar 17, 2017 at 9:54 - also tried using 'click' but doesn't seem to work – Oscar Franco Commented Mar 17, 2017 at 12:14
- as far as I know, all the material-ui ponents should be using onTouchTap because of performance/latency issues – Oscar Franco Commented Mar 17, 2017 at 12:23
1 Answer
Reset to default 6got 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