-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
43 lines (39 loc) · 948 Bytes
/
vitest.setup.ts
File metadata and controls
43 lines (39 loc) · 948 Bytes
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
import { config } from "@vue/test-utils";
import { vi } from "vitest";
// Define Storage interface for TypeScript
interface Storage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
clear(): void;
removeItem(key: string): void;
length: number;
key(index: number): string | null;
}
// Mock localStorage
const localStorageMock: Storage = {
getItem: vi.fn(),
setItem: vi.fn(),
clear: vi.fn(),
removeItem: vi.fn(),
length: 0,
key: vi.fn(),
};
global.localStorage = localStorageMock;
// Mock window.matchMedia
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
// Configure Vue Test Utils
config.global.mocks = {
// Add any global mocks here
};