You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At Facebook, we use Jest to test [React Native](https://reactnative.dev/) applications.
7
7
8
-
Get a deeper insight into testing a working React Native app example by reading the following series: [Part 1: Jest – Snapshot come into play](https://callstack.com/blog/testing-react-native-with-the-new-jest-part-1-snapshots-come-into-play/) and [Part 2: Jest – Redux Snapshots for your Actions and Reducers](https://callstack.com/blog/testing-react-native-with-the-new-jest-part-2-redux-snapshots-for-your-actions-and-reducers/).
8
+
Get a deeper insight into testing a working React Native app example by reading the following series:
9
+
10
+
-[Part 1: Jest – Snapshot come into play](https://callstack.com/blog/testing-react-native-with-the-new-jest-part-1-snapshots-come-into-play/)
11
+
-[Part 2: Jest – Redux Snapshots for your Actions and Reducers](https://callstack.com/blog/testing-react-native-with-the-new-jest-part-2-redux-snapshots-for-your-actions-and-reducers/).
9
12
10
13
## Setup
11
14
12
-
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:
15
+
Starting from react-native version 0.38, a Jest setup is included by default when running `npx @react-native-community/cli init`. The following configuration should be automatically added to your React Native's `jest.config.js` file:
13
16
14
-
```json
15
-
{
16
-
"scripts": {
17
-
"test": "jest"
18
-
},
19
-
"jest": {
20
-
"preset": "react-native"
21
-
}
22
-
}
17
+
```js
18
+
module.exports= {
19
+
preset:'react-native',
20
+
};
23
21
```
24
22
25
23
Run `yarn test` to run tests with Jest.
26
24
27
25
:::tip
28
26
29
-
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.
27
+
If you are upgrading your react-native application and previously used the `jest-react-native`or `react-native`preset, remove the dependency from your `package.json` file and change the preset to `react-native` in `jest.config.js` instead.
30
28
31
29
:::
32
30
@@ -133,7 +131,7 @@ The preset sets up the environment and is very opinionated and based on what we
133
131
134
132
### Environment
135
133
136
-
`react-native` ships with a Jest preset, so the `jest.preset` field of your `package.json` should point to `react-native`. The preset is a node environment that mimics the environment of a React Native app. Because it doesn't load any DOM or browser APIs, it greatly improves Jest's startup time.
134
+
`react-native` ships with a Jest preset, so the `preset` field of your `jest.config.js` should point to `react-native`. The preset is a node environment that mimics the environment of a React Native app. Because it doesn't load any DOM or browser APIs, it greatly improves Jest's startup time.
0 commit comments