react-pure-component-starter
react-pure-component-starter copied to clipboard
Simulating onClick when testing
Thank you for this. I was actually busy implementing my own solution similar to this, but including Redux. Anyway, curious to know how you test components that require user interaction? An example would be onClick. I looked at shallowRender, but then you have to navigate to your children and call the method manually. Not ideal and not elegant.
React has some built-in testing tools, including DOM event simulators that you can call. There's a very good chance I'll add examples of it here, since I've written them for other projects, anyway. =)
That would be awesome. I did try to use TestUtils.Simulate.click
together with Cheerio without any luck. React does not complain about the lack of a DOM when using Cheerio though.
Yeah, the simulate tools need live DOM. You can use JSDom to construct real DOM with React virtual event support.
If you'd like to add a working example here, I'd welcome a PR. =)