Replies: 1 comment 1 reply
-
What I usually do when testing a component using SWR is to not mock SWR itself but the request, also clear the cache between tests, and reduce the deduping interval to zero. beforeEach(() => cache.clear());
test("my test", async () => {
fetch.once(fakeData); // I use https://www.npmjs.com/package/jest-fetch-mock for this
render(<SWRConfig value={{ dedupingInterval: 0 }}><MyComponentUsingSWR some="props" /></SWRConfig>)
await screen.findByText("Some element that only appears after SWR returned the data")
// the rest of your test
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am facing problems in how to mock UseSwr in jest. I have tried few ways f doing it.
By mocking my
[...param]
file. LikeIt does not work. Can't find any material to refer to as well.
Can I get some help? For mocking
useSwr
with jest@namics @sergiodxa
Beta Was this translation helpful? Give feedback.
All reactions