




















@@ -11,11 +11,20 @@ import { waitForever } from "./wait.js";
11111212describe("waitForever", () => {
1313it("creates an unref'ed interval and returns a pending promise", () => {
14-const setIntervalSpy = vi.spyOn(global, "setInterval");
15-const promise = waitForever();
16-expect(setIntervalSpy).toHaveBeenCalledWith(expect.any(Function), 1_000_000);
17-expect(promise).toBeInstanceOf(Promise);
18-setIntervalSpy.mockRestore();
14+const unref = vi.fn();
15+const interval = { unref } as unknown as ReturnType<typeof setInterval>;
16+const setIntervalSpy = vi.spyOn(global, "setInterval").mockReturnValue(interval);
17+try {
18+const promise = waitForever();
19+expect(setIntervalSpy).toHaveBeenCalledTimes(1);
20+const [callback, delay] = setIntervalSpy.mock.calls[0] ?? [];
21+expect(typeof callback).toBe("function");
22+expect(delay).toBe(1_000_000);
23+expect(unref).toHaveBeenCalledTimes(1);
24+expect(promise).toBeInstanceOf(Promise);
25+} finally {
26+setIntervalSpy.mockRestore();
27+}
1928});
2029});
2130此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。