-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest-setup.ts
57 lines (48 loc) · 1.23 KB
/
jest-setup.ts
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
import "@testing-library/jest-dom";
import { setupServer } from "msw/node";
import { handlers } from "./src/__mocks__/handler";
export const server = setupServer(...handlers);
server.events.on("request:start", ({ request }) => {
console.log("MSW intercepted:", request.method, request.url);
});
jest.mock("@/constants", () => ({
API_ENDPOINT: "http://localhost:9090",
WS_ENDPOINT: "ws://localhost:9090",
VAPID_PUBLIC_KEY: "BC7SNZAvIUvYNPc",
}));
globalThis.Notification = {
requestPermission: jest.fn(),
permission: "granted",
} as unknown as jest.Mocked<typeof Notification>;
beforeAll(() => {
server.listen({ onUnhandledRequest: "warn" });
});
afterEach(() => {
server.resetHandlers();
jest.clearAllMocks();
});
afterAll(() => {
jest.resetAllMocks();
server.close();
});
const localStorageMock = (function () {
let store = {} as Storage;
return {
getItem(key: string) {
return store[key];
},
setItem(key: string, value: string) {
store[key] = value;
},
clear() {
store = {} as Storage;
},
removeItem(key: string) {
delete store[key];
},
getAll() {
return store;
},
};
})();
Object.defineProperty(window, "localStorage", { value: localStorageMock });