diff --git a/src/__tests__/useRefresh.test.tsx b/src/__tests__/useRefresh.test.tsx index ef7dbc7..b83e89b 100644 --- a/src/__tests__/useRefresh.test.tsx +++ b/src/__tests__/useRefresh.test.tsx @@ -5,27 +5,31 @@ import { useRefresh } from "../useRefresh"; describe("useRefresh", () => { it("refetch resolves immediately", async () => { - const refetch = async () => {}; + const refetch = jest.fn(async () => {}); const { result } = renderHook(() => useRefresh(refetch)); + expect(refetch).toHaveBeenCalledTimes(0); expect(result.current.refreshing).toEqual(false); await act(async () => { await result.current.onRefresh(); expect(result.current.refreshing).toEqual(true); }); waitFor(() => expect(result.current.refreshing).toEqual(false)); + expect(refetch).toHaveBeenCalledTimes(1); }); it("refetch resolves after 100ms", async () => { - const refetch = () => { + const refetch = jest.fn(() => { return new Promise((resolve) => setTimeout(() => resolve(), 100)); - }; + }); const { result } = renderHook(() => useRefresh(refetch)); + expect(refetch).toHaveBeenCalledTimes(0); expect(result.current.refreshing).toEqual(false); await act(async () => { await result.current.onRefresh(); expect(result.current.refreshing).toEqual(true); }); waitFor(() => expect(result.current.refreshing).toEqual(false)); + expect(refetch).toHaveBeenCalledTimes(1); }); // it("multiple onRefresh calls before refetch resolves", async () => {