feat: reject token if it's not valid

This commit is contained in:
2024-06-15 06:26:13 -04:00
parent dfd709ad1c
commit 5d528fba52
12 changed files with 368 additions and 16 deletions

45
src/libs/lazy.spec.ts Normal file
View File

@@ -0,0 +1,45 @@
import { describe, expect, it } from "bun:test";
import { lazy } from "./lazy";
describe("lazy", () => {
it("lazy value returned when get is called", () => {
const value = lazy(() => "value");
expect(value.get()).toBe("value");
});
it("lazy function not called if get isn't called", () => {
let setValue = false;
lazy(() => {
setValue = true;
return "value";
});
expect(setValue).toBeFalse();
});
it("lazy function called if get is called", () => {
let setValue = false;
lazy(() => {
setValue = true;
return "value";
}).get();
expect(setValue).toBeTrue();
});
it("lazy function called only once if get is called multiple times", () => {
let count = 0;
const value = lazy(() => {
count++;
return "value";
});
const NUM_TIMES_CALLED = 1_000_000;
for (let i = 0; i < NUM_TIMES_CALLED; i++) {
value.get();
}
expect(count).toBe(1);
});
});