Repository navigation
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
52 lines (48 loc) · 1.58 KB
/
Copy pathvitest.setup.ts
File metadata and controls
52 lines (48 loc) · 1.58 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
/**
* Setup for the DOM test project (vitest.config.mts -> "dom").
* jsdom does not implement the browser APIs React and the charting library
* expect, so they are stubbed here.
*/
import { afterEach } from "vitest";
import { cleanup } from "@testing-library/react";
afterEach(() => {
cleanup();
});
if (typeof window !== "undefined") {
if (!window.matchMedia) {
window.matchMedia = ((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => false,
})) as unknown as typeof window.matchMedia;
}
if (!("ResizeObserver" in window)) {
class ResizeObserverStub {
observe(): void {}
unobserve(): void {}
disconnect(): void {}
}
(window as unknown as { ResizeObserver: unknown }).ResizeObserver = ResizeObserverStub;
(globalThis as unknown as { ResizeObserver: unknown }).ResizeObserver = ResizeObserverStub;
}
if (!("IntersectionObserver" in window)) {
class IntersectionObserverStub {
readonly root = null;
readonly rootMargin = "";
readonly thresholds: readonly number[] = [];
observe(): void {}
unobserve(): void {}
disconnect(): void {}
takeRecords(): [] {
return [];
}
}
(window as unknown as { IntersectionObserver: unknown }).IntersectionObserver = IntersectionObserverStub;
(globalThis as unknown as { IntersectionObserver: unknown }).IntersectionObserver = IntersectionObserverStub;
}
}