Testing React Native Apps
At Facebook, we use Jest to test React Native applications.
Get a deeper insight into testing a working React Native app example by reading the following series: Part 1: Jest – Snapshot come into play and Part 2: Jest – Redux Snapshots for your Actions and Reducers.
Setup
Starting from react-native version 0.38, a Jest setup is included by default when running react-native init
. The following configuration should be automatically added to your package.json file:
{
"scripts": {
"test": "jest"
},
"jest": {
"preset": "react-native"
}
}
Run yarn test
to run tests with Jest.
подсказка
If you are upgrading your react-native application and previously used the jest-react-native
preset, remove the dependency from your package.json
file and change the preset to react-native
instead.