forked from solana-foundation/explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-setup.ts
More file actions
33 lines (29 loc) · 1.09 KB
/
test-setup.ts
File metadata and controls
33 lines (29 loc) · 1.09 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
import '@testing-library/jest-dom';
// ResizeObserver is not available in jsdom
if (!globalThis.ResizeObserver) {
globalThis.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};
}
// Needed for @solana/addresses (Solana Kit) which checks isSecureContext before
// using crypto.subtle for PDA derivation. jsdom does not set this to true.
if (!globalThis.isSecureContext) {
Object.defineProperty(globalThis, 'isSecureContext', { value: true });
}
if (!AbortSignal.timeout) {
AbortSignal.timeout = ms => {
const controller = new AbortController();
setTimeout(() => controller.abort(), ms);
return controller.signal;
};
}
// Needed for @solana/web3.js to treat Uint8Arrays as Buffers
// See https://github.com/anza-xyz/solana-pay/issues/106
const originalHasInstance = Uint8Array[Symbol.hasInstance];
Object.defineProperty(Uint8Array, Symbol.hasInstance, {
value(potentialInstance: unknown) {
return originalHasInstance.call(this, potentialInstance) || Buffer.isBuffer(potentialInstance);
},
});