-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
83 lines (75 loc) · 2.03 KB
/
vitest.setup.ts
File metadata and controls
83 lines (75 loc) · 2.03 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
import * as matchers from "@testing-library/jest-dom/matchers";
import { expect, vi } from "vitest";
// Extend Vitest's expect with jest-dom matchers
expect.extend(matchers);
// Mock CSS imports
vi.mock("katex/dist/katex.min.css", () => ({}));
// Mock ResizeObserver
class MockResizeObserver {
observe = vi.fn();
unobserve = vi.fn();
disconnect = vi.fn();
}
globalThis.ResizeObserver =
MockResizeObserver as unknown as typeof ResizeObserver;
// Mock IntersectionObserver
class MockIntersectionObserver {
observe = vi.fn();
unobserve = vi.fn();
disconnect = vi.fn();
root = null;
rootMargin = "";
thresholds = [];
}
globalThis.IntersectionObserver =
MockIntersectionObserver as unknown as typeof IntersectionObserver;
// Mock matchMedia
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
// Mock chrome API
const mockChrome = {
storage: {
local: {
get: vi.fn().mockResolvedValue({}),
set: vi.fn().mockResolvedValue(undefined),
remove: vi.fn().mockResolvedValue(undefined),
},
sync: {
get: vi.fn().mockResolvedValue({}),
set: vi.fn().mockResolvedValue(undefined),
remove: vi.fn().mockResolvedValue(undefined),
},
},
runtime: {
sendMessage: vi.fn(),
onMessage: {
addListener: vi.fn(),
removeListener: vi.fn(),
},
getURL: vi.fn((path: string) => `chrome-extension://test/${path}`),
},
tabs: {
query: vi.fn().mockResolvedValue([]),
sendMessage: vi.fn(),
},
i18n: {
getMessage: vi.fn((key: string) => key),
getUILanguage: vi.fn(() => "en"),
},
};
// @ts-expect-error - Mock chrome global
globalThis.chrome = mockChrome;
// Mock URL.createObjectURL
globalThis.URL.createObjectURL = vi.fn(() => "blob:mock-url");
globalThis.URL.revokeObjectURL = vi.fn();