-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathvitest.setup.js
More file actions
45 lines (39 loc) · 1.06 KB
/
vitest.setup.js
File metadata and controls
45 lines (39 loc) · 1.06 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
import '@testing-library/jest-dom/vitest';
import 'allure-vitest/setup';
import 'fake-indexeddb/auto';
import { default as crypto } from 'crypto';
import { TextDecoder, TextEncoder } from 'util';
global.IntersectionObserver = vi.fn().mockImplementation(function () {
return {
observe: vi.fn(),
disconnect: vi.fn(),
};
});
global.ResizeObserver = vi.fn().mockImplementation(function () {
return {
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;