-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
130 lines (111 loc) · 3.25 KB
/
jest.setup.js
File metadata and controls
130 lines (111 loc) · 3.25 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
126
127
128
129
130
require("@testing-library/jest-native/extend-expect");
const mockAsyncStorage = require("@react-native-async-storage/async-storage/jest/async-storage-mock");
jest.mock("@react-native-async-storage/async-storage", () => mockAsyncStorage);
jest.mock("expo-constants", () => ({
__esModule: true,
default: {
expoConfig: { extra: { oauth: {} }, owner: "owner", slug: "slug" },
},
ExecutionEnvironment: { StoreClient: "store" },
}));
jest.mock("expo-web-browser", () => ({
maybeCompleteAuthSession: jest.fn(),
openAuthSessionAsync: jest.fn(),
openBrowserAsync: jest.fn(),
dismissBrowser: jest.fn(),
}));
jest.mock("expo-linking", () => ({
createURL: jest.fn(() => "https://example.com"),
parse: jest.fn(() => ({})),
addEventListener: jest.fn(() => ({ remove: jest.fn() })),
removeEventListener: jest.fn(),
}));
jest.mock("expo-auth-session", () => ({
makeRedirectUri: jest.fn(() => "https://example.com/callback"),
useAuthRequest: jest.fn(() => [
{ codeVerifier: "verifier" },
null,
jest.fn(),
]),
}));
jest.mock("expo-status-bar", () => ({
StatusBar: () => null,
}));
jest.mock("expo-secure-store", () => ({
getItemAsync: jest.fn(async () => null),
setItemAsync: jest.fn(async () => undefined),
deleteItemAsync: jest.fn(async () => undefined),
}));
jest.mock("expo-router", () => {
const React = require("react");
const Stack = ({ children }) => <>{children}</>;
Stack.Screen = ({ children }) => <>{children}</>;
const Tabs = ({ children }) => <>{children}</>;
Tabs.Screen = ({ children }) => <>{children}</>;
return {
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
back: jest.fn(),
prefetch: jest.fn(),
}),
useLocalSearchParams: jest.fn(() => ({})),
useNavigation: () => ({ setOptions: jest.fn() }),
Stack,
Tabs,
Slot: ({ children }) => <>{children}</>,
router: {
push: jest.fn(),
replace: jest.fn(),
back: jest.fn(),
prefetch: jest.fn(),
},
Link: ({ children }) => <>{children}</>,
};
});
jest.mock("@expo/vector-icons", () => ({
Ionicons: () => null,
}));
jest.mock("react-native-reanimated", () =>
require("react-native-reanimated/mock"),
);
jest.mock("expo-notifications", () => ({
getPermissionsAsync: jest.fn().mockResolvedValue({ status: "granted" }),
requestPermissionsAsync: jest.fn().mockResolvedValue({ status: "granted" }),
setNotificationChannelAsync: jest.fn().mockResolvedValue(null),
AndroidImportance: {
MAX: 4,
},
}));
const { notifyManager } = require("@tanstack/query-core");
notifyManager.setBatchNotifyFunction(fn => fn());
if (typeof window === "undefined") {
global.window = global;
}
if (!window.addEventListener) {
window.addEventListener = jest.fn();
window.removeEventListener = jest.fn();
window.dispatchEvent = jest.fn();
}
if (!global.navigator) {
global.navigator = { onLine: true };
}
global.__DEV__ = true;
const originalError = console.error;
beforeAll(() => {
jest.spyOn(console, "error").mockImplementation((...args) => {
if (
typeof args[0] === "string" &&
args[0].includes("not wrapped in act(")
) {
return;
}
originalError(...args);
});
});
afterAll(() => {
console.error.mockRestore();
});
beforeEach(() => {
jest.clearAllMocks();
});