How do I simulate browser events when writing tests for React js?
javascript, reactjs, testing
Solution
Since version React 0.9, we've included ReactTestUtils which is a small bundle of tools to help you test your components. The most useful part of it is event simulation -- you can run `ReactTestUtils.Simulate.click(node)` in order to simulate a click event using React's synthetic event system.
There's also a few other useful utilities there for making assertions about the DOM structure. Just download the development addons build (`react-with-addons.js`) and pull it out like so:
var ReactTestUtils = React.addons.TestUtils;
ReactTestUtils.Simulate.click(node);
Let me know if anything's unclear here.
Problem
How do I simulate a click on a div element? Or a mouse move? Or text input? How do I do it in a server side nodejs environment, like mocha? And how do I do it in a browser environment, with a runner like karma?