-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathjest.setup.ts
More file actions
187 lines (161 loc) · 5.13 KB
/
Copy pathjest.setup.ts
File metadata and controls
187 lines (161 loc) · 5.13 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import 'react-native-gesture-handler/jestSetup';
// Ensure dev-only code paths such as dynamic imports are skipped
global.__DEV__ = false;
// Mock Sentry to avoid loading native modules during tests
jest.mock('@sentry/react-native', () => ({
init: jest.fn(),
captureException: jest.fn(),
captureMessage: jest.fn(),
addBreadcrumb: jest.fn(),
mobileReplayIntegration: jest.fn(() => ({})),
feedbackIntegration: jest.fn(() => ({})),
wrap: jest.fn((app) => app),
}));
// Provide a mock implementation for react-native-device-info
jest.mock('react-native-device-info', () =>
require('react-native-device-info/jest/react-native-device-info-mock'),
);
// Mock NetInfo to prevent native module errors during tests
jest.mock('@react-native-community/netinfo', () =>
require('@react-native-community/netinfo/jest/netinfo-mock'),
);
// Mock Firebase messaging used in the app container
jest.mock('@react-native-firebase/messaging', () => ({
getMessaging: jest.fn(() => ({
onMessage: jest.fn(),
setBackgroundMessageHandler: jest.fn(),
})),
}));
// Mock version number module
jest.mock('react-native-version-number', () => ({
appVersion: '0.0.0',
}));
// Mock receive sharing intent module
jest.mock('react-native-receive-sharing-intent', () => ({
getReceivedFiles: jest.fn(),
clearReceivedFiles: jest.fn(),
}));
// Mock async storage
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock'),
);
// Mock Expo crypto
jest.mock('expo-crypto', () => ({
digestStringAsync: jest.fn(),
}));
// Mock expo-image to avoid native dependency
jest.mock('expo-image', () => ({
Image: 'Image',
}));
// Mock orientation locker
jest.mock('react-native-orientation-locker', () => ({
addOrientationListener: jest.fn(),
removeOrientationListener: jest.fn(),
getDeviceOrientation: jest.fn(),
lockToPortrait: jest.fn(),
lockToLandscape: jest.fn(),
getInitialOrientation: jest.fn(() => 'PORTRAIT'),
}));
// Mock background timer
jest.mock('react-native-background-timer', () => ({
runBackgroundTimer: jest.fn(),
stopBackgroundTimer: jest.fn(),
}));
// Mock image crop picker
jest.mock('react-native-image-crop-picker', () => ({
openPicker: jest.fn(),
openCamera: jest.fn(),
clean: jest.fn(),
}));
// Mock react-native-permissions
jest.mock('react-native-permissions', () => ({
check: jest.fn(),
request: jest.fn(),
PERMISSIONS: {},
RESULTS: {},
openSettings: jest.fn(),
}));
// Mock react-native-create-thumbnail
jest.mock('react-native-create-thumbnail', () => ({
createThumbnail: jest.fn(),
}));
// Mock expo-linear-gradient
jest.mock('expo-linear-gradient', () => ({
LinearGradient: 'LinearGradient',
}));
// Mock clipboard module
jest.mock('@react-native-clipboard/clipboard', () => ({
getString: jest.fn(),
setString: jest.fn(),
}));
// Mock react-native-webview
jest.mock('react-native-webview', () => 'WebView');
// Mock media controls
jest.mock('react-native-media-controls', () => ({
__esModule: true,
default: () => null,
PLAYER_STATES: {},
}));
// Mock camera roll
jest.mock('@react-native-camera-roll/camera-roll', () => ({
CameraRoll: {
save: jest.fn(),
getPhotos: jest.fn(),
},
}));
// Mock rn-fetch-blob
jest.mock('rn-fetch-blob', () => ({
fs: { dirs: { DocumentDir: '' } },
config: () => ({
fetch: jest.fn(() => Promise.resolve({ path: () => '' })),
}),
}));
// Mock react-native-vision-camera to avoid requiring the native camera module
jest.mock('react-native-vision-camera', () => ({
Camera: 'Camera',
useCameraDevices: jest.fn(() => ({ back: {}, front: {} })),
useCameraPermission: jest.fn(() => ({ hasPermission: true, requestPermission: jest.fn() })),
}));
// Mock bootsplash to bypass native module in tests
jest.mock('react-native-bootsplash', () => ({
hide: jest.fn(),
show: jest.fn(),
getVisibilityStatus: jest.fn(() => 'visible'),
}));
// Mock Expo local authentication
jest.mock('expo-local-authentication', () => ({
authenticateAsync: jest.fn(() => Promise.resolve({ success: true })),
hasHardwareAsync: jest.fn(() => Promise.resolve(true)),
isEnrolledAsync: jest.fn(() => Promise.resolve(true)),
}));
// Mock notifee to prevent native notification module loading
jest.mock('@notifee/react-native', () => ({
__esModule: true,
default: {
onForegroundEvent: jest.fn(),
setBackgroundMessageHandler: jest.fn(),
displayNotification: jest.fn(),
requestPermission: jest.fn(() => Promise.resolve()),
getInitialNotification: jest.fn(() => Promise.resolve(null)),
},
}));
// Mock crypto-js to avoid native WordArray errors in test environment
jest.mock('crypto-js', () => {
const mockCiphertext = {
toString: jest.fn(() => 'mock-encrypted'),
};
return {
AES: {
encrypt: jest.fn(() => mockCiphertext),
decrypt: jest.fn(() => ({ toString: jest.fn(() => '{"data":"mock","stamp":true}') })),
},
enc: {
Base64: { stringify: jest.fn(() => 'bW9jay1lbmNyeXB0ZWQ=') },
Utf8: {
parse: jest.fn((str) => str),
stringify: jest.fn(() => '{"data":"mock","stamp":true}'),
},
},
SHA256: jest.fn(() => ({ toString: jest.fn(() => 'mock-hash') })),
};
});