I'm having issues firing onChange
in Jasmine tests (and using Phantom) with React. The particular issue I am seeing is with a range input. Supposing that a className
changes in a React component after the onChange
event. In Jasmine I am unable to manually fire that onChange
in my tests so that I can then assert the DOM changes.
Everything I have tried so far doesn't work - both using React.addons.TestUtils
or just doing a simple $(node).trigger('change')
on the node in question. I cannot get the onChange
to fire on the React node. Does anyone see anything awry with this sample code, or am I missing something?
For example here would be the sample Jasmine code:
// assuming I already have full access to node and its in the DOM
var node = React.findDOMNode(this.refs.input);
// updating input `value` manually
node.value = 10;
// simulate change to `input` so that `onChange` will fire
React.addons.TestUtils.Simulate.change(node);
// or React.addons.TestUtils.Simulate.change(node, { target: { value: 10 } });
// assert that sample `className` is changed for example, this could be anything - just a simple assertion that something in the DOM changed as expected
expect(node.className).not.toBe('hidden');
I can never get the above expect
to pass - nothing in the DOM is picking up the value
change on the node in question.
Here's also a codepen illustrating the issue: http://codepen.io/bessington/pen/azXwVy
Thanks for your help everyone!