-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
69 lines (61 loc) · 1.82 KB
/
jest.setup.js
File metadata and controls
69 lines (61 loc) · 1.82 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
// jest.setup.js
import "@testing-library/jest-native/extend-expect";
// Polyfill setImmediate and clearImmediate for React Native StatusBar
global.setImmediate =
global.setImmediate || ((fn, ...args) => global.setTimeout(fn, 0, ...args));
global.clearImmediate = global.clearImmediate || global.clearTimeout;
// Mock @react-navigation/native
jest.mock("@react-navigation/native", () => {
return {
...jest.requireActual("@react-navigation/native"),
useNavigation: jest.fn(() => ({
navigate: jest.fn(),
goBack: jest.fn(),
})),
};
});
// Mock StatusBar to prevent clearImmediate issues
jest.mock("react-native/Libraries/Components/StatusBar/StatusBar", () => {
const React = require("react");
return {
__esModule: true,
default: jest.fn(() => null),
};
});
// Suppress console warnings in tests
global.console = {
...console,
warn: jest.fn(),
error: jest.fn(),
};
// Polyfills for React Native
global.setImmediate = global.setTimeout;
global.clearImmediate = global.clearTimeout;
// Mock Linking with all required methods
jest.mock("react-native/Libraries/Linking/Linking", () => ({
openURL: jest.fn(() => Promise.resolve()),
canOpenURL: jest.fn(() => Promise.resolve(true)),
getInitialURL: jest.fn(() => Promise.resolve(null)),
addEventListener: jest.fn(() => ({
remove: jest.fn(),
})),
removeEventListener: jest.fn(),
}));
// Mock SafeAreaView
jest.mock("react-native-safe-area-context", () => ({
SafeAreaView: ({ children }) => children,
}));
// Mock navigation - but simpler since we pass it in tests
jest.mock("@react-navigation/native", () => {
const actualNav = jest.requireActual("@react-navigation/native");
return {
...actualNav,
useNavigation: () => ({
navigate: jest.fn(),
goBack: jest.fn(),
}),
useRoute: () => ({
params: {},
}),
};
});