-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.js
More file actions
125 lines (117 loc) · 3.96 KB
/
jest.setup.js
File metadata and controls
125 lines (117 loc) · 3.96 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
// Jest setup file for React Native SDK tests
// Mock React Native modules
jest.mock('react-native', () => ({
Platform: {
OS: 'ios',
Version: '17.0',
select: jest.fn((options) => options.ios),
},
Dimensions: {
get: jest.fn(() => ({ width: 375, height: 812, scale: 3 })),
},
AppState: {
currentState: 'active',
addEventListener: jest.fn(() => ({ remove: jest.fn() })),
},
Linking: {
getInitialURL: jest.fn().mockResolvedValue(null),
addEventListener: jest.fn(() => ({ remove: jest.fn() })),
},
NativeModules: {
RNDeviceInfo: {
deviceId: 'test-device-id',
model: 'iPhone 14',
systemName: 'iOS',
systemVersion: '17.0',
appVersion: '1.0.0',
buildNumber: '1',
bundleId: 'com.test.app',
isTablet: false,
getUniqueId: jest.fn().mockResolvedValue('test-unique-id'),
},
},
}));
// Mock react-native-device-info
jest.mock('react-native-device-info', () => ({
getUniqueId: jest.fn().mockResolvedValue('test-device-id'),
getModel: jest.fn().mockReturnValue('iPhone 14'),
getSystemName: jest.fn().mockReturnValue('iOS'),
getSystemVersion: jest.fn().mockReturnValue('17.0'),
getVersion: jest.fn().mockReturnValue('1.0.0'),
getBuildNumber: jest.fn().mockReturnValue('1'),
getBundleId: jest.fn().mockReturnValue('com.test.app'),
isTablet: jest.fn().mockReturnValue(false),
getCarrier: jest.fn().mockResolvedValue('Test Carrier'),
getDeviceName: jest.fn().mockResolvedValue('Test Device'),
getManufacturer: jest.fn().mockResolvedValue('Apple'),
getBrand: jest.fn().mockReturnValue('Apple'),
getDeviceType: jest.fn().mockReturnValue('Handset'),
hasNotch: jest.fn().mockReturnValue(true),
getDeviceId: jest.fn().mockReturnValue('iPhone14,2'),
isEmulator: jest.fn().mockResolvedValue(false),
isLandscape: jest.fn().mockResolvedValue(false),
getApplicationName: jest.fn().mockReturnValue('Test App'),
getFirstInstallTime: jest.fn().mockResolvedValue(1704067200000),
getLastUpdateTime: jest.fn().mockResolvedValue(1704067200000),
getTotalMemory: jest.fn().mockResolvedValue(6000000000),
getUsedMemory: jest.fn().mockResolvedValue(2000000000),
getUserAgent: jest.fn().mockResolvedValue('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)'),
}));
// Mock expo-device (optional peer dependency)
jest.mock('expo-device', () => ({
deviceName: 'Test Device',
deviceYearClass: 2023,
isDevice: true,
brand: 'Apple',
manufacturer: 'Apple',
modelName: 'iPhone 14',
modelId: 'iPhone14,2',
osName: 'iOS',
osVersion: '17.0',
osBuildId: '21A5248v',
platformApiLevel: null,
deviceType: 1, // PHONE
}), { virtual: true });
// Mock expo-application (optional peer dependency)
jest.mock('expo-application', () => ({
applicationName: 'Test App',
applicationId: 'com.test.app',
nativeApplicationVersion: '1.0.0',
nativeBuildVersion: '1',
}), { virtual: true });
// Mock @react-native-community/netinfo
jest.mock('@react-native-community/netinfo', () => ({
fetch: jest.fn().mockResolvedValue({
type: 'wifi',
isConnected: true,
isInternetReachable: true,
details: {
ssid: 'TestNetwork',
},
}),
addEventListener: jest.fn(() => jest.fn()),
}));
// Mock @react-native-async-storage/async-storage
jest.mock('@react-native-async-storage/async-storage', () => ({
setItem: jest.fn().mockResolvedValue(null),
getItem: jest.fn().mockResolvedValue(null),
removeItem: jest.fn().mockResolvedValue(null),
multiGet: jest.fn().mockResolvedValue([]),
multiSet: jest.fn().mockResolvedValue(null),
multiRemove: jest.fn().mockResolvedValue(null),
getAllKeys: jest.fn().mockResolvedValue([]),
clear: jest.fn().mockResolvedValue(null),
}));
// Global fetch mock
global.fetch = jest.fn().mockResolvedValue({
ok: true,
json: jest.fn().mockResolvedValue({}),
});
// Silence console during tests (optional - comment out for debugging)
// global.console = {
// ...console,
// log: jest.fn(),
// info: jest.fn(),
// warn: jest.fn(),
// debug: jest.fn(),
// };