Quandoo Unit Testing Tutorial
Enzyme basics
- render types
Jest basics
expect().[comparatorMethod]- Putting it together with enzyme; see
basic.test.js
Testing props with StyledComponents
renderedComponent.props()renderedComponent.find()- DRY:
setup()
Testing event handlers
events.test.js
Mocking modules
mocking.test.js
Mounting / Testing Lifecycle events
lifecycle.test.js
Testing Higher-Order Components
Gotchas
- Object comparison,
toEqual+expect.objectContaining, nottoBe - If spying on prototype object (or in doubt),
jest.clearAllMocks()between each test
Future
- Testing mock-heavy containers
- Testing sagas (i.e. async/generator functions)
On this page
Contributors
Created November 15, 2017
Updated March 8, 2023