-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathjest.setup.ts
45 lines (36 loc) · 1006 Bytes
/
jest.setup.ts
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 { webcrypto } from 'node:crypto';
import { TextDecoder, TextEncoder } from 'util';
const navigatorMock = {};
Object.defineProperty(navigatorMock, 'userAgent', {
get() {
return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0';
},
configurable: true,
});
Object.defineProperty(navigatorMock, 'webdriver', {
get() {
return false;
},
configurable: true,
});
Object.defineProperty(navigatorMock, 'onLine', {
get() {
return true;
},
configurable: true,
});
Object.defineProperty(navigatorMock, 'connection', {
get() {
return { downlink: 10, rtt: 100 };
},
configurable: true,
});
Object.defineProperty(global.window, 'navigator', {
value: navigatorMock,
writable: true,
});
// polyfill TextDecoder, TextEncoder for jsdom >= 16
Object.assign(global, { TextDecoder, TextEncoder });
// polyfill using webcrypto.subtle to fix issue with missing crypto.subtle
// @ts-ignore
globalThis.crypto.subtle = webcrypto.subtle;