Skip to content

Instantly share code, notes, and snippets.

@levchenkod
Created July 2, 2024 23:05
Show Gist options
  • Save levchenkod/8bd4be266608704e29d5c2b8764a17c4 to your computer and use it in GitHub Desktop.
Save levchenkod/8bd4be266608704e29d5c2b8764a17c4 to your computer and use it in GitHub Desktop.
Mock useSWRInfinite with Jest
import useSWRInfinite from "swr/infinite";
jest.mock("swr/infinite");
describe("Page with SWRInfinite", () => {
it("renders", () => {
(useSWRInfinite as jest.Mock).mockResolvedValue({
data: [{ data: [] }],
error: null,
});
//...
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment