-
Notifications
You must be signed in to change notification settings - Fork 1
/
vitest.setup.ts
66 lines (53 loc) · 1.73 KB
/
vitest.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
58
59
60
61
62
63
64
65
66
import "@testing-library/jest-dom/vitest";
import "@testing-library/user-event";
import "@/app/polyfills";
import "intersection-observer";
import "matchmedia-polyfill";
import "matchmedia-polyfill/matchMedia.addListener";
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
import { cleanup } from "@testing-library/react";
import { afterAll, afterEach, beforeAll, beforeEach, vi } from "vitest";
import "@/app/modules/modules";
import { mockServerConfig } from "@/mock-server/constants";
import { server } from "@/mock-server/node";
Object.defineProperty(window, "matchMedia", {
writable: true,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: (query: any) => ({
matches: false,
media: query,
onchange: null,
addListener: () => null,
removeListener: () => null,
addEventListener: () => null,
removeEventListener: () => null,
dispatchEvent: () => null,
}),
});
if (typeof window !== "undefined") {
if (!window.ResizeObserver) {
window.ResizeObserver = ResizeObserverPolyfill;
}
}
if (typeof Element !== "undefined") {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Element.prototype.scrollIntoView = vi.fn<any, typeof Element.prototype.scrollIntoView>();
}
if (typeof document !== "undefined") {
document.queryCommandSupported = () => false;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Element.prototype.scrollTo = vi.fn<any, typeof Element.prototype.scrollTo>();
}
// https://github.com/vitest-dev/vitest/issues/1450
vi.resetModules();
beforeAll(() => {
server.listen(mockServerConfig);
});
beforeEach(() => {});
afterAll(() => {
server.close();
});
afterEach(() => {
server.resetHandlers();
cleanup();
});