ai-code-battle/web/src/test-setup.ts
jedarden 44f6e5c1ec fix(web): add matchMedia mock to prevent unhandled test errors
The window.matchMedia API (used for accessibility features) was not
mocked in tests, causing unhandled rejections when replay.ts tried to
check prefers-reduced-motion. Added the mock to both test-setup.ts
and the beforeEach hook in replay.test.ts to ensure it's available
before modules load.

Closes: bf-5cwi

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 00:18:32 -04:00

21 lines
559 B
TypeScript

/**
* Vitest setup file for browser API mocks.
*/
import { vi } from 'vitest';
// Mock matchMedia for accessibility features in replay.ts
// Must be set up before tests import modules that use it
const matchMediaMock = 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(),
}));
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: matchMediaMock,
});