import '@testing-library/jest-dom/vitest'; import { cleanup } from '@testing-library/react'; import { toHaveNoViolations } from 'jest-axe'; import { afterEach, expect, vi } from 'vitest'; afterEach(cleanup); /* jest-axe ships a plain matcher object, so it plugs into Vitest unchanged. The matcher's type lives in test/vitest.d.ts. */ expect.extend(toHaveNoViolations); /* jsdom implements neither of these, and Radix uses both for positioning and scroll locking. Without the stubs most overlay components throw on render. */ if (!window.matchMedia) { window.matchMedia = vi.fn().mockImplementation((query: string) => ({ matches: false, media: query, onchange: null, addEventListener: vi.fn(), removeEventListener: vi.fn(), dispatchEvent: vi.fn(), addListener: vi.fn(), removeListener: vi.fn(), })); } if (!window.ResizeObserver) { window.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} }; } /* jsdom has no layout engine, so these are absent entirely. cmdk calls scrollIntoView to keep the highlighted item visible, and Radix uses the pointer-capture APIs for drag handling — without the stubs those components throw on render rather than failing a meaningful assertion. */ if (!Element.prototype.scrollIntoView) { Element.prototype.scrollIntoView = vi.fn(); } if (!Element.prototype.hasPointerCapture) { Element.prototype.hasPointerCapture = vi.fn(() => false); Element.prototype.setPointerCapture = vi.fn(); Element.prototype.releasePointerCapture = vi.fn(); }