-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
98 lines (86 loc) · 2.37 KB
/
Copy pathvitest.setup.ts
File metadata and controls
98 lines (86 loc) · 2.37 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import "@testing-library/jest-dom/vitest";
import { cleanup } from "@testing-library/react";
import { afterEach, vi } from "vitest";
// Cleanup after each test
afterEach(() => {
cleanup();
});
// Mock localStorage
const localStorageMock = {
getItem: vi.fn(),
setItem: vi.fn(),
removeItem: vi.fn(),
clear: vi.fn(),
length: 0,
key: vi.fn(),
};
Object.defineProperty(globalThis, "localStorage", {
value: 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(),
})),
});
// Mock ResizeObserver
class ResizeObserverMock {
observe = vi.fn();
unobserve = vi.fn();
disconnect = vi.fn();
}
Object.defineProperty(globalThis, "ResizeObserver", {
value: ResizeObserverMock,
writable: true,
});
// Mock PointerEvent for Radix UI components
class PointerEventMock extends MouseEvent {
pointerId: number;
width: number;
height: number;
pressure: number;
tangentialPressure: number;
tiltX: number;
tiltY: number;
twist: number;
pointerType: string;
isPrimary: boolean;
constructor(type: string, props?: PointerEventInit) {
super(type, props);
this.pointerId = props?.pointerId ?? 0;
this.width = props?.width ?? 1;
this.height = props?.height ?? 1;
this.pressure = props?.pressure ?? 0;
this.tangentialPressure = props?.tangentialPressure ?? 0;
this.tiltX = props?.tiltX ?? 0;
this.tiltY = props?.tiltY ?? 0;
this.twist = props?.twist ?? 0;
this.pointerType = props?.pointerType ?? "mouse";
this.isPrimary = props?.isPrimary ?? false;
}
}
Object.defineProperty(globalThis, "PointerEvent", {
value: PointerEventMock,
writable: true,
});
// Mock scrollIntoView
Element.prototype.scrollIntoView = vi.fn();
// Mock HTMLElement.prototype.hasPointerCapture
HTMLElement.prototype.hasPointerCapture = vi.fn(() => false);
HTMLElement.prototype.setPointerCapture = vi.fn();
HTMLElement.prototype.releasePointerCapture = vi.fn();
// Reset mocks between tests
afterEach(() => {
vi.clearAllMocks();
localStorageMock.getItem.mockReset();
localStorageMock.setItem.mockReset();
localStorageMock.removeItem.mockReset();
});