import { describe, expect, test, vi } from "vitest"; import { throttle } from "../../src"; describe("throttle", () => { test("calls immediately then throttles", async () => { vi.useFakeTimers(); const fn = vi.fn(); const throttled = throttle(fn, 100); throttled(); expect(fn).toHaveBeenCalledTimes(1); throttled(); expect(fn).toHaveBeenCalledTimes(1); vi.advanceTimersByTime(100); throttled(); expect(fn).toHaveBeenCalledTimes(2); vi.useRealTimers(); }); });