-
Notifications
You must be signed in to change notification settings - Fork 9
/
vitest-setup.js
43 lines (38 loc) · 973 Bytes
/
vitest-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
31
32
33
34
35
36
37
38
39
40
41
42
43
fetch = require('node-fetch');
import { vi } from 'vitest';
import '@testing-library/jest-dom/vitest';
window.fetch = fetch;
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
const { getComputedStyle } = window;
window.getComputedStyle = elt => getComputedStyle(elt);
vi.mock('resize-observer-polyfill', () => ({
__esModule: true,
default: vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
})),
}));
vi.mock('lru-cache', () => {
return {
__esModule: true,
default: vi.fn().mockImplementation(() => {
return ({
fetch: vi.fn(),
clear: vi.fn(),
})
})
}
});