-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestSetup.ts
54 lines (46 loc) · 1.84 KB
/
testSetup.ts
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
import "@testing-library/jest-dom";
import "core-js/features/set/is-disjoint-from";
import { noop } from "lodash";
import { setImmediate } from "timers";
// Required for Jest 27
global.setImmediate = setImmediate;
const CSS = class CSS {
private constructor() {
throw new TypeError("CSS is not a constructor");
}
public static [Symbol.toStringTag] = "CSS";
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSS/supports) */
public static supports(property: string, value: string): boolean;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSS/supports) */
public static supports(conditionText: string): boolean;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CSS/supports) */
public static supports(conditionOrProperty: string, value?: string): boolean {
const details = [conditionOrProperty, value]
.filter((arg) => !!arg)
.join(",");
throw new Error(`Not implemented${details && `: `}${details}`);
}
} satisfies Partial<typeof globalThis.CSS>;
Object.assign(globalThis, { CSS });
// NOTE: Including this to prevent noisy console logs from ErrorBoundary components. Even though the ErrorBoundary
// catches the errors, React still logs these to the console unless, `e.defaultPrevented` is `true`
window.addEventListener("error", (e) => {
e.preventDefault();
});
Object.assign(window, {
matchMedia: ((query) => ({
get matches(): boolean {
throw new Error("Not Implemented");
},
media: query,
dispatchEvent: () => true,
addEventListener: noop,
removeEventListener: noop,
addListener: noop,
removeListener: noop,
onchange: null,
})) satisfies Window["matchMedia"],
requestAnimationFrame: (callback: FrameRequestCallback) =>
setTimeout(() => callback(Date.now()), 17),
cancelAnimationFrame: (handle: number) => clearTimeout(handle),
});