Skip to content

Commit 8b99670

Browse files
committed
fix configuration of mocking Reanimated, add additional info
1 parent 6797ba7 commit 8b99670

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

versioned_docs/version-7.x/testing.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,28 @@ To add the mocks, create a file `jest/setup.js` (or any other file name of your
2929
import 'react-native-gesture-handler/jestSetup';
3030

3131
// Include this section for mocking react-native-reanimated
32-
jest.mock('react-native-reanimated', () =>
33-
require('react-native-reanimated/mock')
34-
);
32+
require('react-native-reanimated').setUpTests();
3533

3634
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
3735
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
3836
```
3937

40-
Then we need to use this setup file in our jest config. You can add it under `setupFiles` option in a `jest.config.js` file or the `jest` key in `package.json`:
38+
Then we need to use this setup file in our jest config. You can add it under `setupFilesAfterEnv` option in a `jest.config.js` file or the `jest` key in `package.json`:
4139

4240
```json
4341
{
4442
"preset": "react-native",
45-
"setupFiles": ["<rootDir>/jest/setup.js"]
43+
"setupFilesAfterEnv": ["<rootDir>/jest/setup.js"]
4644
}
4745
```
4846

49-
Make sure that the path to the file in `setupFiles` is correct. Jest will run these files before running your tests, so it's the best place to put your global mocks.
47+
Make sure that the path to the file in `setupFilesAfterEnv` is correct. Jest will run these files before running your tests, so it's the best place to put your global mocks.
48+
49+
:::info
50+
51+
Depending on the versions of React Native Reanimated and Jest you're using, mocking Reanimated might require different configuration - please refer to [the docs of Reanimated](https://docs.swmansion.com/react-native-reanimated/docs/guides/testing#setup) for details.
52+
53+
:::
5054

5155
If your configuration works correctly, you can skip this section, but in some unusual cases you will need to mock `react-native-screens` as well. To add mock of the particular component, e.g. `Screen`, add the following code in `jest/setup.js` file:
5256

0 commit comments

Comments
 (0)