Skip to content

Commit

Permalink
test: fix mocks in node 20
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Apr 20, 2024
1 parent 522689f commit ce5bc04
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/mocks/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { Buffer } from 'buffer'

export function mockCrypto(object: Record<string, unknown>) {
// eslint-disable-next-line no-undef
globalThis.crypto = object as unknown as Crypto
Object.defineProperty(globalThis, 'crypto', {
value: object,
writable: true
})
}

export function mockCryptoFromArray(array: Uint8Array) {
Expand All @@ -19,6 +22,10 @@ export function mockCryptoFromBuffer(buffer: Buffer) {
}

export function resetCrypto() {
// eslint-disable-next-line no-undef, no-undefined
globalThis.crypto = undefined as unknown as Crypto
// eslint-disable-next-line no-undef
Object.defineProperty(globalThis, 'crypto', {
// eslint-disable-next-line no-undefined
value: undefined,
writable: true
})
}

0 comments on commit ce5bc04

Please sign in to comment.