-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
72 lines (60 loc) · 1.59 KB
/
jest.setup.js
File metadata and controls
72 lines (60 loc) · 1.59 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
import "@testing-library/jest-dom/jest-globals";
// Mock Tauri API
const mockInvoke = jest.fn();
jest.mock("@tauri-apps/api/core", () => ({
invoke: mockInvoke,
}));
// Mock Tauri app API
jest.mock("@tauri-apps/api/app", () => ({
setTheme: jest.fn(),
}));
// Mock Tauri image API
jest.mock("@tauri-apps/api/image", () => ({}));
// Mock MUI Joy useColorScheme
jest.mock("@mui/joy", () => ({
...jest.requireActual("@mui/joy"),
useColorScheme: () => ({
mode: "light",
setMode: jest.fn(),
systemMode: "light",
allColorSchemes: ["light", "dark"],
lightColorScheme: "light",
darkColorScheme: "dark",
colorScheme: "light",
setColorScheme: jest.fn(),
}),
}));
// Mock Next.js router
jest.mock("next/router", () => ({
useRouter: () => ({
push: jest.fn(),
pathname: "/",
query: {},
asPath: "/",
}),
}));
// Mock DOM methods
Object.defineProperty(HTMLElement.prototype, "scrollIntoView", {
value: jest.fn(),
writable: true,
});
// Mock URL.createObjectURL
Object.defineProperty(URL, "createObjectURL", {
value: jest.fn(() => "mocked-url"),
writable: true,
});
// Make mockInvoke available globally for tests
global.mockInvoke = mockInvoke;
// Clean up mocks before each test
beforeEach(() => {
mockInvoke.mockClear();
localStorage.clear();
// Reset DOM method mocks
HTMLElement.prototype.scrollIntoView.mockClear &&
HTMLElement.prototype.scrollIntoView.mockClear();
URL.createObjectURL.mockClear && URL.createObjectURL.mockClear();
// Reset console.error mock if it exists
if (console.error.mockClear) {
console.error.mockClear();
}
});