-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
56 lines (50 loc) · 1.52 KB
/
Copy pathvitest.setup.ts
File metadata and controls
56 lines (50 loc) · 1.52 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
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';
import { TextDecoder, TextEncoder } from 'node:util';
import { afterEach } from 'vitest';
afterEach(() => {
if (typeof document !== 'undefined') {
cleanup();
}
});
if (!(new TextEncoder().encode('') instanceof Uint8Array)) {
Object.defineProperty(globalThis, 'TextEncoder', {
configurable: true,
value: TextEncoder,
});
Object.defineProperty(globalThis, 'TextDecoder', {
configurable: true,
value: TextDecoder,
});
}
if (typeof window !== 'undefined') {
if (typeof navigator !== 'undefined' && !('clipboard' in navigator)) {
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: {
writeText: async (_text: string) => undefined,
},
});
}
if (typeof document !== 'undefined' && typeof document.execCommand !== 'function') {
Object.defineProperty(document, 'execCommand', {
configurable: true,
value: (_command: string) => true,
});
}
if (typeof window.requestAnimationFrame !== 'function') {
Object.defineProperty(window, 'requestAnimationFrame', {
configurable: true,
value: (cb: FrameRequestCallback) =>
window.setTimeout(() => cb(performance.now()), 0) as unknown as number,
});
}
if (typeof window.cancelAnimationFrame !== 'function') {
Object.defineProperty(window, 'cancelAnimationFrame', {
configurable: true,
value: (id: number) => {
window.clearTimeout(id);
},
});
}
}