-
Notifications
You must be signed in to change notification settings - Fork 0
Unit, Integration & Snapshot Testing
This app uses Jest with React Native Testing Library for unit and integration tests. It also utilizes snapshot testing.
Jest is a widely used JavaScript unit testing framework that is compatible with TypeScript and React.
Jest Expo is a Jest preset that mocks out the native side of the Expo SDK and handles some of the configuration.
React Native Testing Library is a solution for testing React Native components. It provides light utility functions on top of React Test Renderer.
Redux Mock Store creates a mock Redux store for async action creators using Redux Thunk or other middleware.
Jest Fetch Mock mocks fetch requests to the API.
In the root folder, there is a jest folder with a setup file. This file contains the necessary configuration for React Navigation.
package.json contains additional jest configuration including transformIgnorePatterns.
Snapshot testing renders a UI component, takes a snapshot, then compares it to a reference snapshot file stored alongside the test. The test will fail if the two snapshots do not match.
Snapshots are best used for presentational components that are not often changed.
Read more about writing tests for Redux here.
The jest folder contains a renderWithRedux file, which is a custom render function used to test components which are connected to the Redux store a.k.a. those in the screens folder.