-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathjest.setup.js
More file actions
90 lines (84 loc) · 2.63 KB
/
jest.setup.js
File metadata and controls
90 lines (84 loc) · 2.63 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
// Mock react-native
jest.mock('react-native', () => ({
Platform: { OS: 'ios', select: jest.fn((obj) => obj.ios) },
Linking: {
openURL: jest.fn(() => Promise.resolve()),
openSettings: jest.fn(() => Promise.resolve()),
},
View: 'View',
Text: 'Text',
TouchableOpacity: 'TouchableOpacity',
Modal: 'Modal',
SafeAreaView: 'SafeAreaView',
ScrollView: 'ScrollView',
Switch: 'Switch',
}));
// Mock expo-notifications
jest.mock('expo-notifications', () => ({
setNotificationHandler: jest.fn(),
getPermissionsAsync: jest.fn(() =>
Promise.resolve({ status: 'undetermined' })
),
requestPermissionsAsync: jest.fn(() =>
Promise.resolve({ status: 'granted' })
),
getExpoPushTokenAsync: jest.fn(() =>
Promise.resolve({ data: 'ExponentPushToken[test-token-123]' })
),
setNotificationChannelAsync: jest.fn(() => Promise.resolve()),
scheduleNotificationAsync: jest.fn(() => Promise.resolve('notification-id')),
cancelScheduledNotificationAsync: jest.fn(() => Promise.resolve()),
cancelAllScheduledNotificationsAsync: jest.fn(() => Promise.resolve()),
getBadgeCountAsync: jest.fn(() => Promise.resolve(0)),
setBadgeCountAsync: jest.fn(() => Promise.resolve()),
addNotificationReceivedListener: jest.fn(() => ({ remove: jest.fn() })),
addNotificationResponseReceivedListener: jest.fn(() => ({ remove: jest.fn() })),
removeNotificationSubscription: jest.fn(),
getLastNotificationResponseAsync: jest.fn(() => Promise.resolve(null)),
AndroidImportance: {
HIGH: 4,
DEFAULT: 3,
},
PermissionStatus: {
GRANTED: 'granted',
DENIED: 'denied',
UNDETERMINED: 'undetermined',
},
}));
// Mock expo-device
jest.mock('expo-device', () => ({
isDevice: true,
deviceName: 'Test Device',
}));
// Mock expo-constants
jest.mock('expo-constants', () => ({
expoConfig: {
extra: {
eas: {
projectId: 'test-project-id',
},
},
},
}));
// Mock expo-linking
jest.mock('expo-linking', () => ({
createURL: jest.fn((path) => `teachlink://${path}`),
addEventListener: jest.fn(() => ({ remove: jest.fn() })),
getInitialURL: jest.fn(() => Promise.resolve(null)),
}));
// 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()),
}));
// Silence console warnings during tests
global.console = {
...console,
warn: jest.fn(),
error: jest.fn(),
};