-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathjest-shared-setup.ts
101 lines (96 loc) · 2.62 KB
/
jest-shared-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
// Mock AsyncStorage
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);
// Mock react-native modules that cause issues with Flow types
jest.mock('react-native', () => {
return {
StyleSheet: {
create: (styles: Record<string, any>) => styles,
hairlineWidth: 1,
absoluteFill: {},
flatten: jest.fn()
},
Dimensions: {
get: jest.fn().mockReturnValue({ width: 375, height: 812 }),
addEventListener: jest.fn(),
removeEventListener: jest.fn()
},
Platform: {
OS: 'ios',
select: jest.fn().mockImplementation((obj: { ios?: any; android?: any }) => obj.ios)
},
NativeModules: {
StatusBarManager: { height: 44 }
},
Text: 'Text',
View: 'View',
TouchableOpacity: 'TouchableOpacity',
TouchableWithoutFeedback: 'TouchableWithoutFeedback',
TextInput: 'TextInput',
ScrollView: 'ScrollView',
Image: 'Image',
Animated: {
View: 'Animated.View',
createAnimatedComponent: (component: string) => `Animated.${component}`,
timing: jest.fn().mockReturnValue({ start: jest.fn() }),
Value: jest.fn(() => ({
interpolate: jest.fn(),
setValue: jest.fn()
}))
},
I18nManager: {
isRTL: false
},
useColorScheme: jest.fn().mockReturnValue('light')
};
});
// Mock react-native-svg
jest.mock('react-native-svg', () => {
const mockSvg = () => 'Svg';
mockSvg.Circle = () => 'Circle';
mockSvg.Rect = () => 'Rect';
mockSvg.Path = () => 'Path';
mockSvg.G = () => 'G';
mockSvg.Defs = () => 'Defs';
mockSvg.LinearGradient = () => 'LinearGradient';
mockSvg.Stop = () => 'Stop';
return mockSvg;
});
// Export a function to mock package-specific modules
export const mockThemeContext = (modulePath: string) => {
jest.mock(
modulePath,
() => ({
ThemeContext: {
Provider: ({ children }: { children: React.ReactNode }) => children,
Consumer: ({ children }: { children: Function }) => children({ themeMode: 'light' })
},
useTheme: jest.fn().mockReturnValue({
themeMode: 'light',
colors: {
text: '#000000',
background: '#FFFFFF',
primary: '#3396FF'
}
})
}),
{ virtual: true }
);
};
export const mockUseTheme = (modulePath: string) => {
jest.mock(
modulePath,
() => ({
useTheme: jest.fn().mockReturnValue({
themeMode: 'light',
colors: {
text: '#000000',
background: '#FFFFFF',
primary: '#3396FF'
}
})
}),
{ virtual: true }
);
};