-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-setup.ts
More file actions
56 lines (52 loc) · 1.42 KB
/
Copy pathtest-setup.ts
File metadata and controls
56 lines (52 loc) · 1.42 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
const noop = () => {};
if (typeof globalThis.ResizeObserver === 'undefined') {
globalThis.ResizeObserver = class ResizeObserverStub {
observe() {}
unobserve() {}
disconnect() {}
} as unknown as typeof ResizeObserver;
}
if (typeof globalThis.IntersectionObserver === 'undefined') {
globalThis.IntersectionObserver = class IntersectionObserverStub {
constructor() {}
observe() {}
unobserve() {}
disconnect() {}
takeRecords() {
return [];
}
} as unknown as typeof IntersectionObserver;
}
if (typeof window !== 'undefined' && typeof window.matchMedia === 'undefined') {
window.matchMedia = ((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: noop,
removeListener: noop,
addEventListener: noop,
removeEventListener: noop,
dispatchEvent: () => false,
})) as unknown as typeof window.matchMedia;
}
if (typeof document !== 'undefined') {
const proto = Object.getPrototypeOf(document.createRange());
if (proto && typeof proto.getClientRects !== 'function') {
proto.getClientRects = function () {
return { length: 0, item: () => null, [Symbol.iterator]: function* () {} };
};
proto.getBoundingClientRect = function () {
return {
x: 0,
y: 0,
left: 0,
top: 0,
right: 0,
bottom: 0,
width: 0,
height: 0,
toJSON: () => ({}),
};
};
}
}