Learn more about Mintlify
Enter your email to receive updates about new features and product releases.
Create and use mock functions in tests
import { test, expect, mock } from "bun:test"; test("mock function", () => { const fn = mock((x: number) => x * 2); fn(5); fn(10); expect(fn).toHaveBeenCalledTimes(2); expect(fn).toHaveBeenCalledWith(5); });
import { test, expect, spyOn } from "bun:test"; const obj = { method: (x: number) => x * 2 }; test("spy on method", () => { const spy = spyOn(obj, "method"); obj.method(5); expect(spy).toHaveBeenCalledWith(5); });