-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
73 lines (67 loc) · 1.94 KB
/
Copy pathjest.setup.js
File metadata and controls
73 lines (67 loc) · 1.94 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
// Use fake timers to prevent Animated API from leaking open handles
jest.useFakeTimers();
// Mock Expo Router for tests
jest.mock('expo-router', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
back: jest.fn(),
canGoBack: jest.fn(() => true),
}),
useLocalSearchParams: () => ({}),
useNavigation: () => ({
setOptions: jest.fn(),
navigate: jest.fn(),
goBack: jest.fn(),
}),
Stack: {
Screen: ({ children }) => children ?? null,
},
Link: ({ children }) => children,
}));
// Mock @expo/vector-icons
jest.mock('@expo/vector-icons', () => {
const React = require('react');
const { Text } = require('react-native');
const MockIcon = (props) => React.createElement(Text, props, props.name);
return {
Ionicons: MockIcon,
MaterialIcons: MockIcon,
FontAwesome: MockIcon,
};
});
// Mock expo-haptics
jest.mock('expo-haptics', () => ({
impactAsync: jest.fn(),
notificationAsync: jest.fn(),
selectionAsync: jest.fn(),
ImpactFeedbackStyle: { Light: 'light', Medium: 'medium', Heavy: 'heavy' },
NotificationFeedbackType: { Success: 'success', Warning: 'warning', Error: 'error' },
}));
// Mock AsyncStorage
jest.mock('@react-native-async-storage/async-storage', () => ({
setItem: jest.fn(() => Promise.resolve()),
getItem: jest.fn(() => Promise.resolve(null)),
removeItem: jest.fn(() => Promise.resolve()),
clear: jest.fn(() => Promise.resolve()),
getAllKeys: jest.fn(() => Promise.resolve([])),
multiGet: jest.fn(() => Promise.resolve([])),
multiSet: jest.fn(() => Promise.resolve()),
multiRemove: jest.fn(() => Promise.resolve()),
}));
// Silence specific warnings in tests
const originalWarn = console.warn;
beforeAll(() => {
console.warn = (...args) => {
if (
args[0]?.includes?.('react-native-screens') ||
args[0]?.includes?.('useNativeDriver')
) {
return;
}
originalWarn(...args);
};
});
afterAll(() => {
console.warn = originalWarn;
});