3 ms·
Do you use any tools to make the assertions on the resulting DOM simpler? What about any components that maintain internal state; do you just step them through
by shepmaster 10y ago
Do you use any tools to make the assertions on the resulting DOM simpler?
What about any components that maintain internal state; do you just step them through the states and assert the DOM state as well?
- cjcenizal 10y agoI built this testing tool at a previous employer: https://github.com/smaato/react-test-kit https://github.com/smaato/react-test-kit. It's very very simple, it just exposes jQuery-like methods for querying the DOM (and internally uses Sizzle). Here's an example of how we used react-test-kit to test a SearchBox component: https://github.com/smaato/ui-framework/blob/develop/src/framework/searchBox/SearchBox.spec.jsx https://github.com/smaato/ui-framework/blob/develop/src/fram... Here's the interactive component example: http://smaato.github.io/ui-framework/#/searchbox http://smaato.github.io/ui-framework/#/searchbox
- analyst74 10y agoI find it simplest to use shallow rendering in my unit tests as opposed to rendering the DOM, so the output I have to verify only contains things the component-under-test renders. As for shallow render, you can use either the default Test Utilities or Enzyme, I personally find Enzyme's shallow render implementation much easier to work with.