Skip to content
Source
Sign inSign up
samwillis/one-million-boxes
Open History to see the last commit

setup.ts

49 lines1.0 KB

1import "@testing-library/jest-dom/vitest"
2​
3// Mock localStorage for tests
4const localStorageMock = {
5 getItem: vi.fn(),
6 setItem: vi.fn(),
7 removeItem: vi.fn(),
8 clear: vi.fn(),
9 length: 0,
10 key: vi.fn(),
12​
13Object.defineProperty(globalThis, `localStorage`, {
14 value: localStorageMock,
15 writable: true,
16})
17​
18// Mock matchMedia for tests
19Object.defineProperty(window, `matchMedia`, {
20 writable: true,
21 value: vi.fn().mockImplementation((query: string) => ({
22 matches: false,
23 media: query,
24 onchange: null,
25 addListener: vi.fn(),
26 removeListener: vi.fn(),
27 addEventListener: vi.fn(),
28 removeEventListener: vi.fn(),
29 dispatchEvent: vi.fn(),
30 })),
31})
32​
33// Mock ResizeObserver for tests
34class ResizeObserverMock {
35 observe = vi.fn()
36 unobserve = vi.fn()
37 disconnect = vi.fn()
39​
40Object.defineProperty(globalThis, `ResizeObserver`, {
41 value: ResizeObserverMock,
42 writable: true,
43})
44​
45// Mock navigator.vibrate for tests
46Object.defineProperty(navigator, `vibrate`, {
47 value: vi.fn().mockReturnValue(true),
48 writable: true,
49})