Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 2, 2023
1 parent f9312e8 commit 2ae86a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/internals/getNonce.crypto.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect, test } from "vitest";

test("with crypto", async () => {
const before = global.crypto;

global.crypto = {
randomUUID: () => "test",
} as any;
const { getNonce } = await import("./getNonce.js");

expect(getNonce()).toBe("test");

global.crypto = before;
});
15 changes: 15 additions & 0 deletions src/internals/getNonce.nocrypto.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect, test } from "vitest";

test("without crypto", async () => {
const before = global.crypto;

global.crypto = undefined as any;

const { getNonce } = await import("./getNonce.js");

expect(getNonce().length).toBeGreaterThan(20);

global.crypto = before;
});
1 change: 0 additions & 1 deletion src/internals/getNonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const randomString = () => Math.random().toString(36).slice(2);

export type GetNonce = () => TsonNonce;

// istanbul ignore next
export const getNonce: GetNonce =
typeof crypto === "object" && typeof crypto.randomUUID === "function"
? () => crypto.randomUUID() as TsonNonce
Expand Down

0 comments on commit 2ae86a7

Please sign in to comment.