-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
33 lines (29 loc) · 1.07 KB
/
vitest.setup.ts
File metadata and controls
33 lines (29 loc) · 1.07 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
/// <reference types="vitest" />
import "@testing-library/jest-dom";
// Ensure React act warnings are suppressed in the test environment.
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
// Radix Tooltip and Drawer use ResizeObserver; jsdom doesn't provide it by default.
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
const globalWithRO = globalThis as typeof globalThis & { ResizeObserver?: typeof ResizeObserver };
globalWithRO.ResizeObserver = ResizeObserver;
// matchMedia is used in responsive guards; jsdom doesn't implement it.
const globalWithMM = globalThis as typeof globalThis & {
matchMedia?: (query: string) => MediaQueryList;
};
if (!globalWithMM.matchMedia) {
globalWithMM.matchMedia = (query: string) =>
({
matches: false,
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
}) as unknown as MediaQueryList;
}