forked from anhquoc2010/react_native_boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest-setup.tsx
114 lines (94 loc) · 3.73 KB
/
jest-setup.tsx
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
import React from 'react';
import 'react-native-gesture-handler/jestSetup';
import '@testing-library/jest-native/extend-expect';
require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests();
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock'),
);
jest.mock('react-native-device-info', () => ({
...jest.requireActual('react-native-device-info/jest/react-native-device-info-mock'),
// getVersion: jest.fn().mockReturnValue('1.0.0'),
// getBuildNumber: jest.fn().mockReturnValue(1),
}));
jest.mock('@sentry/react-native', () => ({
init: jest.fn(),
ReactNativeTracing: jest.fn(),
ReactNavigationInstrumentation: jest.fn(),
setUser: jest.fn(),
flush: jest.fn(),
wrap: jest.fn().mockImplementation(component => component),
createReduxEnhancer: jest.fn().mockReturnValue(function (next: any) {
return function (reducer: any, initialState: any) {
return next(reducer, initialState);
};
}),
}));
jest.mock('react-native-encrypted-storage', () => ({
setItem: jest.fn(() => Promise.resolve()),
getItem: jest.fn(() => Promise.resolve('{ "foo": 1 }')),
removeItem: jest.fn(() => Promise.resolve()),
clear: jest.fn(() => Promise.resolve()),
}));
jest.mock('react-native-localize', () => require('react-native-localize/mock.js'));
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
// jest.mock('@react-native-firebase/app', () => ({
// messaging: jest.fn(() => ({
// hasPermission: jest.fn(() => Promise.resolve(true)),
// subscribeToTopic: jest.fn(),
// unsubscribeFromTopic: jest.fn(),
// requestPermission: jest.fn(() => Promise.resolve(true)),
// getToken: jest.fn(() => Promise.resolve('myMockToken')),
// onMessage: jest.fn(),
// })),
// analytics: jest.fn(() => ({
// logEvent: jest.fn(),
// setUserProperties: jest.fn(),
// setUserId: jest.fn(),
// setCurrentScreen: jest.fn(),
// })),
// }));
jest.mock('redux-persist', () => ({
...jest.requireActual('redux-persist'),
persistReducer: jest.fn().mockImplementation((config, reducers) => reducers),
persistStore: jest.fn().mockImplementation(store => store),
}));
jest.mock('redux-persist/integration/react', () => ({
PersistGate: (props: any) => props.children,
}));
jest.mock('@react-native-community/hooks', () => ({
...jest.requireActual('@react-native-community/hooks'),
useAccessibilityInfo: jest.fn().mockReturnValue({ reduceMotion: false }),
}));
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('@gorhom/bottom-sheet', () => {
const react = require('react-native');
return {
...require('@gorhom/bottom-sheet/mock'),
BottomSheetFlatList: react.FlatList,
BottomSheetSectionList: react.SectionList,
};
});
jest.mock('react-native-safe-area-context', () => ({
...jest.requireActual('react-native-safe-area-context'),
useSafeAreaInsets: jest.fn().mockImplementation(() => ({
left: 0,
right: 0,
bottom: 0,
top: 0,
})),
}));
jest.mock('@react-navigation/drawer', () => ({
createDrawerNavigator: jest.fn().mockReturnValue({
Navigator: ({ children }: any) => <>{children}</>,
Screen: ({ children }: any) => <>{children}</>,
}),
DrawerContentScrollView: ({ children }: any) => <>{children}</>,
DrawerItemList: ({ children }: any) => <>{children}</>,
}));
jest.mock('react-native-navigation-bar-color');
jest.mock('@react-native-community/netinfo', () =>
require('@react-native-community/netinfo/jest/netinfo-mock.js'),
);
global.app.fetch = jest.fn();