feat: reject token if it's not valid
This commit is contained in:
45
src/libs/lazy.spec.ts
Normal file
45
src/libs/lazy.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user