vitest swr #4114
vitest swr
#4114
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Please help me to test custom swr hook using vitest. When i run test below it appears to hang. "debug1" is printed in the console but "debug2" is not. When eventually test comes back it prints following error in the console: Error: Worker terminated due to reaching memory limit: JS heap out of memory. All other tests i have run just fine. I also get this error if i run just one single test.
import { renderHook } from "@testing-library/react";
import useSWR from "swr";
import { Mock, describe, expect, it, vi } from "vitest";
import { useCompanies } from "./company";
// Mocking swr
vi.mock("swr", () => {
console.log("Mocking useSWR");
const mockUseSWR = vi.fn(() => {
console.log("Mock useSWR called");
return {
data: { "1": { count: 10 } },
error: undefined,
isLoading: false,
mutate: vi.fn(),
isValidating: false,
};
});
return {
default: mockUseSWR,
useSWR: mockUseSWR,
};
});
console.log("debug1");
describe("useCompanies", () => {
it("should fetch and return data", async () => {
console.log("debug2");
});
});
thank you
Beta Was this translation helpful? Give feedback.
All reactions