-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
58 lines (54 loc) · 1.56 KB
/
Copy pathvitest.setup.ts
File metadata and controls
58 lines (54 loc) · 1.56 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
49
50
51
52
53
54
55
56
57
58
import '@testing-library/jest-dom/vitest';
import { cleanup } from '@testing-library/react';
import { afterEach } from 'vitest';
// @testing-library/react auto-cleans only when Vitest globals are enabled;
// we run with globals: false, so wire cleanup explicitly here.
afterEach(() => {
cleanup();
});
// jsdom lacks matchMedia — MUI's useMediaQuery needs it.
if (typeof window !== 'undefined' && !window.matchMedia) {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
}),
});
}
// jsdom lacks IntersectionObserver — used by some MUI components.
if (typeof globalThis.IntersectionObserver === 'undefined') {
class MockIntersectionObserver {
observe() {}
unobserve() {}
disconnect() {}
takeRecords() { return []; }
root = null;
rootMargin = '';
thresholds = [];
}
Object.defineProperty(globalThis, 'IntersectionObserver', {
writable: true,
configurable: true,
value: MockIntersectionObserver,
});
}
// jsdom lacks ResizeObserver — used by MUI for layout-aware components.
if (typeof globalThis.ResizeObserver === 'undefined') {
class MockResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
Object.defineProperty(globalThis, 'ResizeObserver', {
writable: true,
configurable: true,
value: MockResizeObserver,
});
}