Reading: Class 36 – Application State Testing with Jest - mwilkin-401-advanced-javascript/bend-javascript-401d2 GitHub Wiki
Testing a React-Redux app using Jest and Enzyme
-
Jest – Unit testing framework for React.js
-
Babel-jest: for support of ES6 and ES7.
-
Enzyme -JS testing utility to make it easier to assert React Components.
Advantages of using Jest for a testing environment:
- Easy to set up
- Able to run in parallel with development
- Fast running testing framework
- Snapshot testing: reduces the number of tests necessary, able to track changes in the various components
- Built in matchers, spies, and an extensive mocking library (including manual module mocks, timer mocks, and ES6 class mocks)
- Jasmine is used for assertion
- Supports TypeScript
- Built in Coverage reports
- Does Delta Testing with watch
- Very to migrate from other testing solutions
Reducer - a pure function that takes the previous state and an action, and returns the next state.
-
Pure functions are easy to test: they don’t have side-effects, don’t rely on external state and will always return the same output.
-
- Usually where the business logic should happen.
-
- Where new application state is formed based on external (API) or internal response.
-
Having unit tests for all reducers will prevent any issues related to global application state.
-
Especially useful if there are a lot of different API calls and every call will modify a state.