These tools help us achieve our goal of confidence from our tests.
Jest helps us achieve our goal of confidence by giving us the headless browser of js-dom. By rendering our components on a DOM, we’re more closely replicating how our components are used in production.
React Testing Library helps us achieve our goal of confidence by:
- Closely mirroring how the user actually will experience the code, by:
- Rendering it to a real DOM
- Running it within React's true lifecycle and source code
- Only supporting queries and APIs that resemble what a real user would see
- For example, real DOM properties, as opposed to React props (of which the user does not care about)
By giving use Jest matchers that rely on true DOM properties, our assertions more closely represent what would actually be seen in a browser.
This library helps us achieve our goal of confidence for more complicated React hooks, by giving us APIs that closely replicate how a hook will be used by a component.