-
Notifications
You must be signed in to change notification settings - Fork 637
Expand file tree
/
Copy pathjest-setup.ts
More file actions
103 lines (96 loc) · 2.88 KB
/
jest-setup.ts
File metadata and controls
103 lines (96 loc) · 2.88 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
/* eslint-disable ts/ban-ts-comment */
/* eslint-disable no-restricted-globals */
// Mock react-native-worklets first
jest.mock('react-native-worklets', () => ({
__esModule: true,
default: {},
}));
// Mock react-native-reanimated
jest.mock('react-native-reanimated', () => {
const View = require('react-native').View;
return {
__esModule: true,
default: {
View,
ScrollView: View,
createAnimatedComponent: (component: any) => component,
},
useSharedValue: jest.fn(() => ({ value: 0 })),
useAnimatedStyle: jest.fn(fn => fn()),
withTiming: jest.fn(value => value),
withSpring: jest.fn(value => value),
withDecay: jest.fn(value => value),
withDelay: jest.fn((_, value) => value),
withRepeat: jest.fn(value => value),
withSequence: jest.fn((...values) => values[0]),
cancelAnimation: jest.fn(),
Easing: {
linear: jest.fn(),
ease: jest.fn(),
quad: jest.fn(),
cubic: jest.fn(),
bezier: jest.fn(),
in: jest.fn(fn => fn),
out: jest.fn(fn => fn),
inOut: jest.fn(fn => fn),
},
FadeIn: { duration: jest.fn(() => ({})) },
FadeOut: { duration: jest.fn(() => ({})) },
FadeInDown: { duration: jest.fn(() => ({})) },
FadeInUp: { duration: jest.fn(() => ({})) },
FadeInLeft: { duration: jest.fn(() => ({})) },
FadeInRight: { duration: jest.fn(() => ({})) },
SlideInDown: { duration: jest.fn(() => ({})) },
SlideInUp: { duration: jest.fn(() => ({})) },
SlideInLeft: { duration: jest.fn(() => ({})) },
SlideInRight: { duration: jest.fn(() => ({})) },
Layout: {},
Keyframe: jest.fn(),
};
});
// Mock expo-localization
jest.mock('expo-localization', () => ({
getLocales: jest.fn(() => [
{
languageTag: 'en-US',
languageCode: 'en',
textDirection: 'ltr',
digitGroupingSeparator: ',',
decimalSeparator: '.',
measurementSystem: 'metric',
currencyCode: 'USD',
currencySymbol: '$',
regionCode: 'US',
},
]),
}));
// Mock react-native-mmkv
jest.mock('react-native-mmkv', () => ({
MMKV: jest.fn(() => ({
set: jest.fn(),
getString: jest.fn(),
getNumber: jest.fn(),
getBoolean: jest.fn(),
delete: jest.fn(),
clearAll: jest.fn(),
getAllKeys: jest.fn(() => []),
})),
useMMKVString: jest.fn((_key: string) => [undefined, jest.fn()]),
useMMKVNumber: jest.fn((_key: string) => [undefined, jest.fn()]),
useMMKVBoolean: jest.fn((_key: string) => [undefined, jest.fn()]),
useMMKVObject: jest.fn((_key: string) => [undefined, jest.fn()]),
createMMKV: jest.fn(() => ({
set: jest.fn(),
getString: jest.fn(),
getNumber: jest.fn(),
getBoolean: jest.fn(),
delete: jest.fn(),
clearAll: jest.fn(),
getAllKeys: jest.fn(() => []),
})),
}));
// Global window object setup for React Native testing
// @ts-expect-error
global.window = {};
// @ts-expect-error
global.window = global;