| |
| |
| |
| import '@testing-library/jest-dom/vitest'; |
| import { beforeEach, vi } from 'vitest'; |
|
|
| |
| Object.defineProperty(window, 'matchMedia', { |
| writable: true, |
| value: vi.fn().mockImplementation((query: string) => ({ |
| matches: false, |
| media: query, |
| onchange: null, |
| addListener: vi.fn(), |
| removeListener: vi.fn(), |
| addEventListener: vi.fn(), |
| removeEventListener: vi.fn(), |
| dispatchEvent: vi.fn(), |
| })), |
| }); |
|
|
| |
| globalThis.ResizeObserver = vi.fn().mockImplementation(() => ({ |
| observe: vi.fn(), |
| unobserve: vi.fn(), |
| disconnect: vi.fn(), |
| })) as unknown as typeof ResizeObserver; |
|
|
| |
| globalThis.IntersectionObserver = vi.fn().mockImplementation(() => ({ |
| observe: vi.fn(), |
| unobserve: vi.fn(), |
| disconnect: vi.fn(), |
| })) as unknown as typeof IntersectionObserver; |
|
|
| |
| window.scrollTo = vi.fn(); |
|
|
| |
| const localStorageState = new Map<string, string>(); |
| const localStorageMock = { |
| getItem: vi.fn((key: string) => localStorageState.get(key) ?? null), |
| setItem: vi.fn((key: string, value: string) => { |
| localStorageState.set(key, value); |
| }), |
| removeItem: vi.fn((key: string) => { |
| localStorageState.delete(key); |
| }), |
| clear: vi.fn(() => { |
| localStorageState.clear(); |
| }), |
| key: vi.fn((index: number) => Array.from(localStorageState.keys())[index] ?? null), |
| get length() { |
| return localStorageState.size; |
| }, |
| }; |
| Object.defineProperty(window, 'localStorage', { |
| writable: true, |
| value: localStorageMock, |
| }); |
|
|
| beforeEach(() => { |
| localStorageState.clear(); |
| localStorageMock.getItem.mockClear(); |
| localStorageMock.setItem.mockClear(); |
| localStorageMock.removeItem.mockClear(); |
| localStorageMock.clear.mockClear(); |
| localStorageMock.key.mockClear(); |
| }); |
|
|