import 'vitest-axe/extend-expect' import { expect } from 'vitest' import * as matchers from 'vitest-axe/matchers' // Register vitest-axe's `toHaveNoViolations` matcher so a11y tests can call // `expect(await axe(node)).toHaveNoViolations()`. expect.extend(matchers) // Deterministic crypto polyfill (mirrors tests/setup.ts) so generateIdempotencyKey() // returns a stable value across component-test runs without bringing in the // router mock from tests/setup.ts. if (!globalThis.crypto) { ;(globalThis as { crypto: Crypto }).crypto = { randomUUID: () => '00000000-0000-4000-8000-000000000000', getRandomValues: (buf: Uint8Array) => { for (let i = 0; i < buf.length; i++) buf[i] = 0 return buf }, } as unknown as Crypto } // JSDOM's `Element.scrollIntoView` is not implemented by default; Vuetify's // list/menu components call it during opening transitions. Stub it so the // test environment doesn't throw. if (typeof Element !== 'undefined' && !Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = () => undefined // JSDOM's `getBoundingClientRect` returns zeros, which is fine for most // assertions but breaks Vuetify positioning math in some menus. Provide a // minimal viewport size on document body so anchored components can render. if (typeof document !== 'undefined') { Object.defineProperty(document.body, 'getBoundingClientRect', { configurable: true, value: () => ({ top: 0, left: 0, right: 1024, bottom: 768, width: 1024, height: 768, x: 0, y: 0, toJSON: () => ({}) }), }) } // `window.visualViewport` is consulted by Vuetify; happy-dom has it but // jsdom does not. Stub the minimum surface the lib reads. if (typeof window !== 'undefined' && !window.visualViewport) { Object.defineProperty(window, 'visualViewport', { configurable: true, value: { width: 1024, height: 768, offsetLeft: 0, offsetTop: 0, scale: 1, addEventListener: () => undefined, removeEventListener: () => undefined }, }) } // `ResizeObserver` is required by Vuetify VOverlay and friends; jsdom lacks it. if (typeof globalThis.ResizeObserver === 'undefined') { ;(globalThis as { ResizeObserver: unknown }).ResizeObserver = class ResizeObserver { observe(): void { /* noop */ } unobserve(): void { /* noop */ } disconnect(): void { /* noop */ } } }