-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.setup.ts
54 lines (48 loc) · 1.39 KB
/
tests.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
import { expect, afterEach, vi } from "vitest";
import { cleanup } from "@testing-library/react";
import * as matchers from "@testing-library/jest-dom/matchers";
import "@testing-library/jest-dom";
// extends Vitest's expect method with methods from react-testing-library
expect.extend(matchers);
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
Object.defineProperty(window, "computedStyle", {
writable: true,
value: vi.fn().mockImplementation(() => {}),
});
const { getComputedStyle } = window;
window.getComputedStyle = (elt) => getComputedStyle(elt);
vi.mock("react-i18next", () => ({
// this mock makes sure any components using the translate hook can use it without a warning being shown
useTranslation: () => {
return {
t: (str: string) => str,
i18n: {
changeLanguage: () => new Promise(() => {}),
language: "en",
},
};
},
initReactI18next: {
type: "3rdParty",
init: () => {},
},
}));
vi.mock("@vitjs/runtime", () => ({
__esModule: true,
}));
// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup();
});