mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 10:00:44 +00:00
test: tighten wait forever interval assertion
This commit is contained in:
@@ -11,11 +11,20 @@ import { waitForever } from "./wait.js";
|
||||
|
||||
describe("waitForever", () => {
|
||||
it("creates an unref'ed interval and returns a pending promise", () => {
|
||||
const setIntervalSpy = vi.spyOn(global, "setInterval");
|
||||
const promise = waitForever();
|
||||
expect(setIntervalSpy).toHaveBeenCalledWith(expect.any(Function), 1_000_000);
|
||||
expect(promise).toBeInstanceOf(Promise);
|
||||
setIntervalSpy.mockRestore();
|
||||
const unref = vi.fn();
|
||||
const interval = { unref } as unknown as ReturnType<typeof setInterval>;
|
||||
const setIntervalSpy = vi.spyOn(global, "setInterval").mockReturnValue(interval);
|
||||
try {
|
||||
const promise = waitForever();
|
||||
expect(setIntervalSpy).toHaveBeenCalledTimes(1);
|
||||
const [callback, delay] = setIntervalSpy.mock.calls[0] ?? [];
|
||||
expect(typeof callback).toBe("function");
|
||||
expect(delay).toBe(1_000_000);
|
||||
expect(unref).toHaveBeenCalledTimes(1);
|
||||
expect(promise).toBeInstanceOf(Promise);
|
||||
} finally {
|
||||
setIntervalSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user