-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvitest.setup.js
39 lines (33 loc) · 975 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
import '@testing-library/jest-dom/vitest';
import { default as crypto } from 'crypto';
import { TextDecoder, TextEncoder } from 'util';
global.IntersectionObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
disconnect: vi.fn(),
}));
global.ResizeObserver = vi.fn().mockImplementation(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
unobserve: vi.fn(),
}));
Object.defineProperty(global, 'crypto', {
value: {
randomUUID: () => '42',
getRandomValues: (arr) => crypto.randomFillSync(arr),
},
});
Object.defineProperty(global, 'jest', {
value: {
mock: vi.mock,
restoreAllMocks: vi.resetAllMocks,
clearAllMocks: vi.clearAllMocks,
clearAllTimers: vi.clearAllTimers,
useFakeTimers: vi.useFakeTimers,
runAllTimersAsync: vi.runAllTimersAsync,
runOnlyPendingTimersAsync: vi.runOnlyPendingTimersAsync,
spyOn: vi.spyOn,
fn: vi.fn,
},
});
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;