-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathjsdom.mocks.ts
More file actions
62 lines (53 loc) · 1.49 KB
/
Copy pathjsdom.mocks.ts
File metadata and controls
62 lines (53 loc) · 1.49 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
59
60
61
62
/* oxlint-disable no-console */
import '@testing-library/jest-dom';
const { getComputedStyle } = window;
window.getComputedStyle = (elt) => getComputedStyle(elt);
window.HTMLElement.prototype.scrollIntoView = () => {};
// jsdom does not implement media playback and logs an error without these stubs.
window.HTMLMediaElement.prototype.play = () => Promise.resolve();
window.HTMLMediaElement.prototype.pause = () => {};
window.HTMLMediaElement.prototype.load = () => {};
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
window.ResizeObserver = ResizeObserver;
if (!document.fonts) {
Object.defineProperty(document, 'fonts', {
writable: true,
value: {
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
},
});
}
const originalConsoleError = console.error;
console.error = (...data) => {
if (
typeof data[0]?.toString === 'function' &&
data[0].toString().includes('Error: Could not parse CSS stylesheet')
) {
return;
}
originalConsoleError(...data);
};
class IntersectionObserver {
observe() {}
unobserve() {}
disconnect() {}
}
window.IntersectionObserver = IntersectionObserver as any;