25 lines
746 B
TypeScript
25 lines
746 B
TypeScript
import { afterEach, describe, expect, mock, test } from "bun:test";
|
|
import { delay } from "../src/utils/delay";
|
|
|
|
describe("delay", () => {
|
|
const originalNodeEnv = process.env.NODE_ENV;
|
|
const originalSetTimeout = globalThis.setTimeout;
|
|
|
|
afterEach(() => {
|
|
process.env.NODE_ENV = originalNodeEnv;
|
|
globalThis.setTimeout = originalSetTimeout;
|
|
});
|
|
|
|
test("does not schedule throttle timers during tests", async () => {
|
|
process.env.NODE_ENV = "test";
|
|
const setTimeoutMock = mock(() => {
|
|
throw new Error("setTimeout should not be called during tests");
|
|
});
|
|
globalThis.setTimeout = setTimeoutMock as unknown as typeof setTimeout;
|
|
|
|
await delay(1000);
|
|
|
|
expect(setTimeoutMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|