-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #706 from retejs/add-tests
Add tests
- Loading branch information
Showing
10 changed files
with
429 additions
and
245 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { jest } from '@jest/globals' | ||
import { Buffer } from 'buffer' | ||
|
||
export function mockCrypto(object: Record<string, unknown>) { | ||
// eslint-disable-next-line no-undef | ||
globalThis.crypto = object as unknown as Crypto | ||
} | ||
|
||
export function mockCryptoFromArray(array: Uint8Array) { | ||
mockCrypto({ | ||
getRandomValues: jest.fn().mockReturnValue(array) | ||
}) | ||
} | ||
|
||
export function mockCryptoFromBuffer(buffer: Buffer) { | ||
mockCrypto({ | ||
randomBytes: jest.fn().mockReturnValue(buffer) | ||
}) | ||
} | ||
|
||
export function resetCrypto() { | ||
// eslint-disable-next-line no-undef, no-undefined | ||
globalThis.crypto = undefined as unknown as Crypto | ||
} |
Oops, something went wrong.