mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
25 lines
620 B
TypeScript
25 lines
620 B
TypeScript
import { expect, mock, test } from "bun:test";
|
|
|
|
const random1 = mock(() => Math.random());
|
|
const random2 = mock(() => Math.random());
|
|
|
|
test("clearing all mocks", () => {
|
|
random1();
|
|
random2();
|
|
|
|
expect(random1).toHaveBeenCalledTimes(1);
|
|
expect(random2).toHaveBeenCalledTimes(1);
|
|
|
|
mock.clearAllMocks();
|
|
|
|
expect(random1).toHaveBeenCalledTimes(0);
|
|
expect(random2).toHaveBeenCalledTimes(0);
|
|
|
|
// Note: implementations are preserved
|
|
expect(typeof random1()).toBe("number");
|
|
expect(typeof random2()).toBe("number");
|
|
|
|
expect(random1).toHaveBeenCalledTimes(1);
|
|
expect(random2).toHaveBeenCalledTimes(1);
|
|
});
|