-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
93 lines (77 loc) · 2.74 KB
/
jest.setup.js
File metadata and controls
93 lines (77 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import '@testing-library/jest-native/extend-expect';
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js';
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
import { jest } from '@jest/globals';
jest.mock('@react-native-community/netinfo', () => mockRNCNetInfo);
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
jest.doMock('@sentry/react-native', () => ({
init: jest.fn(),
}));
jest.doMock('react-native-reanimated', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Reanimated = require('react-native-reanimated/mock');
// The mock for `call` immediately calls the callback which is incorrect
// So we override it with a no-op
Reanimated.default.call = () => {};
return Reanimated;
});
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('nanoid/non-secure', () => ({
nanoid: () => 'routeUniqId',
}));
const FRAME_TIME = 10;
global.requestAnimationFrame = (cb) => {
setTimeout(cb, FRAME_TIME);
};
jest.mock('react-native/Libraries/Components/Switch/Switch', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mockComponent = require('react-native/jest/mockComponent');
return mockComponent('react-native/Libraries/Components/Switch/Switch');
});
jest.mock('react-native-gesture-handler', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const View = require('react-native/Libraries/Components/View/View');
return {
Swipeable: View,
DrawerLayout: View,
State: {},
ScrollView: View,
Slider: View,
Switch: View,
TextInput: View,
ToolbarAndroid: View,
ViewPagerAndroid: View,
DrawerLayoutAndroid: View,
WebView: View,
NativeViewGestureHandler: View,
TapGestureHandler: View,
FlingGestureHandler: View,
ForceTouchGestureHandler: View,
LongPressGestureHandler: View,
PanGestureHandler: View,
PinchGestureHandler: View,
RotationGestureHandler: View,
/* Buttons */
RawButton: View,
BaseButton: View,
RectButton: View,
BorderlessButton: View,
/* Other */
FlatList: View,
gestureHandlerRootHOC: () => null,
Directions: {},
};
});
beforeEach(() => {
global.fetch = jest.fn((...args) => {
console.warn('global.fetch needs to be mocked in tests', ...args);
throw new Error('global.fetch needs to be mocked in tests');
});
});
//clean up after the tests are finished
afterEach(() => {
global.fetch.mockRestore();
//reset any requests handlers that we may add during the tests,
//so they don't affect other tests.
});