-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjest.setup.js
More file actions
97 lines (89 loc) · 3.28 KB
/
Copy pathjest.setup.js
File metadata and controls
97 lines (89 loc) · 3.28 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
import "@testing-library/jest-native/extend-expect";
// Mock AsyncStorage
jest.mock("@react-native-async-storage/async-storage", () =>
require("@react-native-async-storage/async-storage/jest/async-storage-mock"),
);
// Mock expo modules
jest.mock("expo-constants", () => ({
default: {
manifest: {
extra: {},
},
expoConfig: {
extra: {},
},
},
}));
// expo-location ships untransformed ESM, so any suite that transitively imports
// the attendance stack fails to parse it. Several suites already declared their
// own `jest.mock("expo-location", …)` for exactly this reason; this is that same
// stub as a default, so a new import in the attendance chain does not break
// unrelated suites. A file-level jest.mock still wins, so the suites that stub
// specific position helpers are unaffected.
jest.mock("expo-location", () => ({
__esModule: true,
Accuracy: { Balanced: 3, Highest: 6 },
getForegroundPermissionsAsync: jest.fn(() =>
Promise.resolve({ status: "denied" }),
),
getBackgroundPermissionsAsync: jest.fn(() =>
Promise.resolve({ status: "denied" }),
),
requestForegroundPermissionsAsync: jest.fn(() =>
Promise.resolve({ status: "denied" }),
),
getCurrentPositionAsync: jest.fn(() =>
Promise.reject(new Error("location unavailable in tests")),
),
getLastKnownPositionAsync: jest.fn(() => Promise.resolve(null)),
}));
// expo-sqlite ships untransformed ESM and reaches for the native bridge, so any
// suite that transitively imports the offline queue would fail to parse it.
// This default keeps those suites working without boilerplate; the two suites
// that actually exercise the queue override it with the WASM-backed mock in
// test-utils/expoSqliteMock.js, and a file-level jest.mock wins over this one.
jest.mock("expo-sqlite", () => ({
__esModule: true,
openDatabaseAsync: jest.fn(() =>
Promise.reject(new Error("expo-sqlite is not mocked in this suite")),
),
}));
// NetInfo's real module reaches for the native bridge at import time. The
// default is "online", so a test that never touches connectivity behaves as it
// would with a working connection; tests that care override these.
jest.mock("@react-native-community/netinfo", () => ({
__esModule: true,
default: {
fetch: jest.fn(() =>
Promise.resolve({
isConnected: true,
isInternetReachable: true,
type: "wifi",
}),
),
addEventListener: jest.fn(() => jest.fn()),
},
}));
jest.mock("@react-native-firebase/messaging", () => {
const messagingInstance = {
registerDeviceForRemoteMessages: jest.fn(() => Promise.resolve()),
requestPermission: jest.fn(() => Promise.resolve(1)),
getToken: jest.fn(() => Promise.resolve("test-fcm-token")),
deleteToken: jest.fn(() => Promise.resolve()),
onTokenRefresh: jest.fn(() => jest.fn()),
onMessage: jest.fn(() => jest.fn()),
onNotificationOpenedApp: jest.fn(() => jest.fn()),
getInitialNotification: jest.fn(() => Promise.resolve(null)),
setBackgroundMessageHandler: jest.fn(),
AuthorizationStatus: {
NOT_DETERMINED: -1,
DENIED: 0,
AUTHORIZED: 1,
PROVISIONAL: 2,
EPHEMERAL: 3,
},
};
const messaging = () => messagingInstance;
messaging.AuthorizationStatus = messagingInstance.AuthorizationStatus;
return messaging;
});