Hacker News new | ask | show | jobs
by shepmaster 3632 days 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?

2 comments

I built this testing tool at a previous employer: 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/fram...

Here's the interactive component example: http://smaato.github.io/ui-framework/#/searchbox

I 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.