forked from babylonlabs-io/simple-staking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
35 lines (31 loc) · 1.08 KB
/
jest.setup.js
File metadata and controls
35 lines (31 loc) · 1.08 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
const { TextEncoder, TextDecoder } = require("util");
// Mock TextEncoder/TextDecoder which are available in browsers but not in Node.js environment
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
// For handling issues with libraries that check for existence of crypto.subtle
if (typeof global.crypto !== "object") {
global.crypto = {
subtle: {},
getRandomValues: (arr) => {
return require("crypto").randomFillSync(arr);
},
};
}
// Mock fetch API if needed but without requiring node-fetch
if (typeof global.fetch !== "function") {
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve({}),
text: () => Promise.resolve(""),
blob: () => Promise.resolve(new Blob()),
arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
}),
);
global.Headers = jest.fn().mockImplementation(() => ({}));
global.Request = jest.fn().mockImplementation(() => ({}));
global.Response = jest.fn().mockImplementation(() => ({
json: () => Promise.resolve({}),
text: () => Promise.resolve(""),
}));
}