-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.js
30 lines (26 loc) · 1018 Bytes
/
setup.js
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
import { configure } from '@testing-library/dom';
import '@testing-library/jest-dom'
// import { jestPreviewConfigure } from 'jest-preview'
// jestPreviewConfigure({ autoPreview: true })
configure({ throwSuggestions: true })
export function setup(viOrJest) {
if (window == null) throw Error("`window` is null. Perhaps you are not using JSDOM? Or perhaps you are calling this function before the window has been mocked by JSDOM.")
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: viOrJest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: viOrJest.fn(), // deprecated
removeListener: viOrJest.fn(), // deprecated
addEventListener: viOrJest.fn(),
removeEventListener: viOrJest.fn(),
dispatchEvent: viOrJest.fn(),
})),
});
globalThis.ResizeObserver = class ResizeObserver {
observe () { viOrJest.fn() }
unobserve () { viOrJest.fn() }
disconnect () { viOrJest.fn() }
}
}