-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
71 lines (66 loc) · 2.02 KB
/
Copy pathjest.setup.js
File metadata and controls
71 lines (66 loc) · 2.02 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
// jest.setup.js
// 1. Mock AsyncStorage
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);
// 2. Mock TurboModuleRegistry to fix "DevMenu" and "SettingsManager" missing errors
// This is required because jest.requireActual('react-native') tries to initialize native modules
jest.mock('react-native/Libraries/TurboModule/TurboModuleRegistry', () => {
const turboModuleRegistry = jest.requireActual(
'react-native/Libraries/TurboModule/TurboModuleRegistry',
);
return {
...turboModuleRegistry,
getEnforcing: (name) => {
// DevMenu is missing in the test environment
if (name === 'DevMenu') {
return null;
}
// SettingsManager is missing in the test environment (used by Platform/Settings)
if (name === 'SettingsManager') {
return {
settings: {},
getConstants: () => ({
settings: {},
}),
};
}
return turboModuleRegistry.getEnforcing(name);
},
};
});
// 3. Mock Animated to run immediately (Synchronously)
// This prevents "act(...)" warnings by skipping the animation duration
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');
const mockAnimation = (value, config) => ({
start: (callback) => {
// Apply the end value immediately
value.setValue(config.toValue);
// Trigger the completion callback
if (callback) {
callback({ finished: true });
}
},
});
return {
...RN,
Animated: {
...RN.Animated,
timing: mockAnimation,
spring: mockAnimation,
parallel: (animations) => ({
start: (callback) => {
animations.forEach(a => a.start());
if (callback) callback({ finished: true });
}
}),
sequence: (animations) => ({
start: (callback) => {
animations.forEach(a => a.start());
if (callback) callback({ finished: true });
}
}),
},
};
});