JS Testing with Jest and React
Published Thursday, April 05, 2018
A code reading by @gj
Jest
- New hotness for testing React
- More or less a superset of Jasmine
- Backed by Facebook
- “Just works” out of the box
- Started as a wrapper around JSDom, evolved into its own thing
Hopes and dreams: Jest makes test writing fun and easy => we write more tests
Helpful features
- Watch mode (
--watch
) - runs test on code changes (similar toguard
on server-side) - Coverage metrics (
--coverage
) - out of the box - Notifications mode (
--notify
) - native OS notification when test runs completes - Tracks test failures - runs failed tests first on next run (shorter feedback loop)
- Tracks test suite run time - suites run in parallel across processes
- Fully sandboxed - tests are strictly scoped, so no globals pollution
Suggestions
- Enzyme’s
shallow
overmount
for rendering components
WIP… more to follow after next week’s code reading.