-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest.setup.ts
115 lines (103 loc) · 3.16 KB
/
jest.setup.ts
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import mockDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock';
import i18next from './lib/i18n';
import { initReactI18next } from 'react-i18next';
jest.mock('react-native-device-info', () => ({
...mockDeviceInfo,
getBundleId: () => 'com.unit-test.app',
}));
jest.mock('./src/common/testID', () => ({
tID: (id: string) => id,
}));
jest.mock('@react-native-community/netinfo', () => mockRNCNetInfo);
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock'),
);
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('react-native-reanimated', () =>
require('react-native-reanimated/mock'),
);
jest.mock('react-native-gesture-handler', () => {
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,
TouchableOpacity: View,
/* Other */
FlatList: View,
gestureHandlerRootHOC: jest.fn(),
Directions: {},
GestureHandlerRootView: View,
};
});
jest.mock('react-native-notifications', () => ({
Notifications: {
getInitialNotification: jest.fn(),
isRegisteredForRemoteNotifications: jest.fn(),
registerRemoteNotifications: jest.fn(),
events: jest.fn(() => ({
registerRemoteNotificationsRegistered: jest.fn(),
registerRemoteNotificationsRegistrationDenied: jest.fn(),
registerRemoteNotificationsRegistrationFailed: jest.fn(),
})),
},
NotificationBackgroundFetchResult: { NEW_DATA: 'NEW_DATA' },
}));
jest.mock('@react-navigation/elements', () => ({
useHeaderHeight: jest.fn(),
}));
jest.mock('@react-navigation/native', () => ({
...jest.requireActual('@react-navigation/native'),
useNavigation: jest.fn(),
useFocusEffect: jest.fn(),
createNavigationContainerRef: jest.fn(),
}));
beforeAll(async () => {
// Setup minimal i18next instance
jest.useRealTimers(); // Required to deal with hook timeout bug
return i18next.use(initReactI18next).init({
fallbackLng: 'en',
supportedLngs: ['en'],
react: {
useSuspense: true,
},
ns: ['common'],
defaultNS: 'common',
interpolation: {
escapeValue: false,
},
resources: {
en: {
common: {
// Plurals are an uncommon case where a defaultValue is not provided
'post-comments_zero': 'COMMENT',
'post-comments_one': '1 COMMENT',
'post-comments_other': '{{count}} COMMENTS',
'post-replies_zero': 'REPLY',
},
},
},
});
});