-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
41 lines (37 loc) · 1.03 KB
/
vitest.setup.ts
File metadata and controls
41 lines (37 loc) · 1.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
// ABOUTME: Vitest setup file for test environment initialization
// ABOUTME: Imports jest-dom matchers and configures window.matchMedia mock
import '@testing-library/jest-dom'
import { vi } from 'vitest'
// Mock matchMedia for theme tests
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
// Mock localStorage
const localStorageMock = (() => {
let store: Record<string, string> = {}
return {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value.toString()
},
removeItem: (key: string) => {
delete store[key]
},
clear: () => {
store = {}
},
}
})()
Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
})