-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
48 lines (42 loc) · 1.41 KB
/
Copy pathvitest.setup.ts
File metadata and controls
48 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// third-party
import "@testing-library/jest-dom/vitest"
import { cleanup } from "@testing-library/react"
import { toHaveNoViolations } from "jest-axe"
import { afterEach, expect, vi } from "vitest"
// jest-axe custom matcher -> `expect(...).toHaveNoViolations()`
// `toHaveNoViolations` is already a { toHaveNoViolations } matcher object.
expect.extend(toHaveNoViolations)
// Unmount React trees between tests to avoid cross-test DOM leakage.
afterEach(() => {
cleanup()
})
// --- jsdom polyfills required by Base UI primitives ---------------------
// Base UI uses ResizeObserver to measure collapsible panel heights.
if (!("ResizeObserver" in globalThis)) {
globalThis.ResizeObserver = class {
observe() {}
unobserve() {}
disconnect() {}
} as unknown as typeof ResizeObserver
}
// matchMedia (prefers-reduced-motion, responsive hooks).
if (!window.matchMedia) {
Object.defineProperty(window, "matchMedia", {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(),
removeListener: vi.fn(),
dispatchEvent: vi.fn(),
}),
})
}
// jsdom does not implement layout; stub the animation/measurement APIs
// Base UI touches so open/close transitions do not throw.
if (!Element.prototype.scrollIntoView) {
Element.prototype.scrollIntoView = vi.fn()
}