test: quiet and speed up test runs
This commit is contained in:
24
packages/core/test/delay.test.ts
Normal file
24
packages/core/test/delay.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user