forked from tahowallet/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupJest.ts
36 lines (32 loc) · 921 Bytes
/
setupJest.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
import * as util from "util"
import Dexie from "dexie"
// ref: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
// ref: https://github.com/jsdom/jsdom/issues/2524
Object.defineProperty(window, "TextEncoder", {
writable: true,
value: util.TextEncoder,
})
Object.defineProperty(window, "TextDecoder", {
writable: true,
value: util.TextDecoder,
})
Object.defineProperty(window.navigator, "usb", {
writable: true,
value: {
getDevices: () => [],
addEventListener: () => {},
},
})
// Prevent Dexie from caching indexedDB global so fake-indexeddb
// can reset properly.
Object.defineProperty(Dexie.dependencies, "indexedDB", {
get: () => indexedDB,
})
// Stub fetch calls
Object.defineProperty(window, "fetch", {
writable: true,
value: (url: string) => {
// eslint-disable-next-line no-console
console.warn("Uncaught fetch call to: \n", url)
},
})