mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-15 03:01:02 +00:00
22 lines
841 B
TypeScript
22 lines
841 B
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createCachedLazyValueGetter } from "./lazy-value.js";
|
|
|
|
describe("createCachedLazyValueGetter", () => {
|
|
it("memoizes lazy factories", () => {
|
|
const resolveSchema = vi.fn(() => ({ type: "object" as const }));
|
|
const getSchema = createCachedLazyValueGetter(resolveSchema);
|
|
|
|
expect(getSchema()).toEqual({ type: "object" });
|
|
expect(getSchema()).toEqual({ type: "object" });
|
|
expect(resolveSchema).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("uses the fallback when the lazy value resolves nullish", () => {
|
|
const fallback = { type: "object" as const, properties: {} };
|
|
const resolveSchema = (): typeof fallback | undefined => undefined;
|
|
const getSchema = createCachedLazyValueGetter(resolveSchema, fallback);
|
|
|
|
expect(getSchema()).toBe(fallback);
|
|
});
|
|
});
|