New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React TestUtils Simulate change doesn't change checked state of checkbox #242
Comments
Not a bug. I didn't understand that there was another value you could send to the Simulate functions to pass in the event. To get the click to show that the checkbox changed I can do this: TestUtils.Simulate.change(checkbox.getDOMNode(), {"target": {"checked": true}}); |
ran into this issue to. the trick is that you need to set all the event data that your handler expects to be there as part of the second argument to the change command. i.e. if your event handler is checking |
@richard-flosi Thanks for the explanation! That let me finally solve my issue with checkbox testing! ;-) |
@richard-flosi please provide a short example |
@kurumkan I think @dangerbell example looks right.
So, just make sure the second argument, the object, contains all the data that your |
With the example above my handler receives a dummy target, this won't pass Flow type checks needed to access eventTarget.checked
Even if I hack
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm not sure if this is a React Simulate thing or if it's something to do with how the DOM works in Jest.
I have a simple test to click a checkbox and report the new state back to the component. It worked fine in the browser but the Simulate.change didn't report the new state.
This example shows the error happening on just the checkbox:
I expect to see 'true' in the console and that's what happens in the browser (Chrome & FireFox), but not in the test.
In my understanding the change handler is supposed to happen after the state change on the element.
The test shows the same behaviour if I use a "controlled" or an "uncontrolled" component. And shows the same behaviour if I simulate a click event and use a click handler.
The text was updated successfully, but these errors were encountered: