-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
217 lines (202 loc) · 5.42 KB
/
jest.setup.js
File metadata and controls
217 lines (202 loc) · 5.42 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Jest setup file for React Native testing
// Mock AsyncStorage
jest.mock("@react-native-async-storage/async-storage", () =>
require("@react-native-async-storage/async-storage/jest/async-storage-mock"),
);
// Mock expo-secure-store
jest.mock("expo-secure-store", () => ({
getItemAsync: jest.fn(),
setItemAsync: jest.fn(),
deleteItemAsync: jest.fn(),
}));
// Mock expo-constants
jest.mock("expo-constants", () => ({
expoConfig: {
extra: {},
},
}));
// Mock expo-image(Jest 不转译 expo-modules-core;用 RN Image 即可跑测)
jest.mock("expo-image", () => {
const { Image } = require("react-native");
return {
__esModule: true,
Image,
};
});
// Mock react-native-reanimated
jest.mock("react-native-reanimated", () => {
const Reanimated = require("react-native-reanimated/mock");
Reanimated.default.call = () => {};
return Reanimated;
});
// Mock react-native-gesture-handler
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,
RawButton: View,
BaseButton: View,
RectButton: View,
BorderlessButton: View,
FlatList: View,
gestureHandlerRootHOC: jest.fn(),
Directions: {},
};
});
// Mock @shopify/react-native-skia
jest.mock("@shopify/react-native-skia", () => ({
Skia: {
Image: {
MakeImageFromEncoded: jest.fn(),
},
Paint: jest.fn(),
Path: jest.fn(),
Canvas: jest.fn(),
},
Canvas: "Canvas",
Path: "Path",
SkImage: "SkImage",
useImage: jest.fn(),
useFont: jest.fn(),
}));
// Mock expo-router
jest.mock("expo-router", () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
back: jest.fn(),
}),
useLocalSearchParams: () => ({}),
Link: "Link",
Stack: "Stack",
Tabs: "Tabs",
usePathname: jest.fn(() => "/"),
}));
// Mock Supabase
jest.mock("@supabase/supabase-js", () => ({
createClient: jest.fn(() => ({
auth: {
signInWithPassword: jest.fn(),
signOut: jest.fn(),
getSession: jest.fn(),
onAuthStateChange: jest.fn(() => ({
data: { subscription: { unsubscribe: jest.fn() } },
})),
},
from: jest.fn(() => ({
select: jest.fn(() => ({
eq: jest.fn(() => ({
single: jest.fn(),
order: jest.fn(),
})),
order: jest.fn(),
})),
insert: jest.fn(() => ({ select: jest.fn() })),
update: jest.fn(() => ({ eq: jest.fn() })),
delete: jest.fn(() => ({ eq: jest.fn() })),
})),
})),
}));
// Mock react-native-safe-area-context
jest.mock("react-native-safe-area-context", () => ({
SafeAreaProvider: ({ children }) => children,
SafeAreaView: ({ children }) => children,
useSafeAreaInsets: () => ({ top: 0, right: 0, bottom: 0, left: 0 }),
}));
// Mock expo-audio
jest.mock("expo-audio", () => ({
PermissionStatus: {
GRANTED: "granted",
DENIED: "denied",
UNDETERMINED: "undetermined",
},
AudioStatus: {
isLoaded: true,
isPlaying: false,
isBuffering: false,
duration: 0,
currentTime: 0,
},
createAudioPlayer: jest.fn(() => ({
play: jest.fn(),
pause: jest.fn(),
stop: jest.fn(),
seek: jest.fn(),
dispose: jest.fn(),
addListener: jest.fn(),
removeAllListeners: jest.fn(),
})),
useAudioPlayer: jest.fn(),
useAudioPlayerStatus: jest.fn(),
requestRecordingPermissionsAsync: jest.fn().mockResolvedValue({ granted: true }),
getRecordingPermissionsAsync: jest.fn().mockResolvedValue({ granted: true }),
}));
// Mock expo-haptics
jest.mock("expo-haptics", () => ({
impactAsync: jest.fn(),
ImpactFeedbackStyle: {
Light: "light",
Medium: "medium",
Heavy: "heavy",
},
notificationAsync: jest.fn(),
NotificationFeedbackType: {
success: "success",
warning: "warning",
error: "error",
},
}));
// Mock expo-modules-core (required by expo-haptics and expo-audio)
jest.mock("expo-modules-core", () => ({
EventEmitter: jest.fn().mockImplementation(() => ({
addListener: jest.fn(),
removeAllListeners: jest.fn(),
})),
NativeModulesProxy: {},
requireNativeModule: jest.fn(),
requireOptionalNativeModule: jest.fn(),
}));
// Mock expo-file-system
jest.mock("expo-file-system", () => ({
cacheDirectory: "/mock-cache/",
documentDirectory: "/mock-documents/",
copyAsync: jest.fn(),
deleteAsync: jest.fn(),
getInfoAsync: jest.fn().mockResolvedValue({ exists: false }),
readAsStringAsync: jest.fn(),
writeAsStringAsync: jest.fn(),
makeDirectoryAsync: jest.fn(),
downloadAsync: jest.fn(),
createDownloadResumable: jest.fn(),
}));
// Mock expo-file-system/legacy
jest.mock("expo-file-system/legacy", () => ({
cacheDirectory: "/mock-cache/",
documentDirectory: "/mock-documents/",
copyAsync: jest.fn(),
deleteAsync: jest.fn(),
getInfoAsync: jest.fn().mockResolvedValue({ exists: false }),
readAsStringAsync: jest.fn(),
writeAsStringAsync: jest.fn(),
makeDirectoryAsync: jest.fn(),
downloadAsync: jest.fn(),
createDownloadResumable: jest.fn(),
}));