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
// The mock for `call` immediately calls the callback which is incorrect
36
-
// So we override it with a no-op
37
-
Reanimated.default.call= () => {};
38
-
39
-
return Reanimated;
33
+
require('react-native-reanimated/mock');
40
34
});
41
35
42
36
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
@@ -54,53 +48,160 @@ Then we need to use this setup file in our jest config. You can add it under `se
54
48
55
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.
56
50
51
+
If your configuration works correctly, you can skip this section, but in some unusual cases you will need to mock `react-native-screen` as well. To do so add the following code in `jest/setup.js` file:
52
+
53
+
```js
54
+
// Include this section form mocking react-native-screens
55
+
jest.mock('react-native-screens', () => {
56
+
// Require actual module instead of a mock
57
+
let screens =jest.requireActual('react-native-screens');
58
+
59
+
// All exports in react-native-screens are getters
60
+
// We cannot use spread for cloning as it will call the getters
61
+
// So we need to clone it with Object.create
62
+
screens =Object.create(
63
+
Object.getPrototypeOf(screens),
64
+
Object.getOwnPropertyDescriptors(screens)
65
+
);
66
+
67
+
return screens;
68
+
});
69
+
```
70
+
57
71
If you're not using Jest, then you'll need to mock these modules according to the test framework you are using.
58
72
59
73
## Writing tests
60
74
61
75
We recommend using [React Native Testing Library](https://callstack.github.io/react-native-testing-library/) along with [`jest-native`](https://github.com/testing-library/jest-native) to write your tests.
62
76
63
-
Example:
77
+
We are going to write example tests for Root Navigator defined below:
For writing tests that include times functions you will need to use [Fake Timers](https://jestjs.io/docs/timer-mocks). They will replace times function implementation to use time from the fake clock.
0 commit comments