-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvitest-setup-client.ts
53 lines (49 loc) · 1.1 KB
/
vitest-setup-client.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
import '@testing-library/jest-dom/vitest'
import { vi } from 'vitest'
// Mock window object if it doesn't exist
if (!global.window) {
global.window = {
matchMedia: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
scrollTo: vi.fn(),
scrollY: 0,
innerHeight: 768,
} as any
}
// Mock document object if it doesn't exist
if (!global.document) {
global.document = {
...window.document,
createElement: vi.fn().mockImplementation((tag) => ({
setAttribute: vi.fn(),
getElementsByTagName: vi.fn().mockReturnValue([]),
id: '',
textContent: '',
offsetTop: 0,
animate: vi.fn().mockReturnValue({
pause: vi.fn(),
play: vi.fn(),
finished: Promise.resolve(),
}),
})),
} as any
}
// Mock HTMLElement if it doesn't exist
if (!global.HTMLElement) {
global.HTMLElement = class HTMLElement {
animate() {
return {
pause: vi.fn(),
play: vi.fn(),
finished: Promise.resolve(),
}
}
} as any
}
// add more mocks here if you need them