Replies: 1 comment
-
Hi. Typically, you wouldn't mock the query function, but intercept the actual network request and mock the response using a tool like Mock Service Worker. The issue with fetch being undefined sounds like an issue with your test environment. Dominik has written about this too: https://tkdodo.eu/blog/testing-react-query#mocking-network-requests |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
So I was introducing react-query for one of big projects and I had this weird behaviour inside tests. My tests are using jest and rtl.
I have query fn which is function which calls "fetch" api and return promise. I was trying to mock this function in test. What surprise me is that when I run tests I was getting error "fetch is undefined". Its weird situation because like I said above I used jest to mock this function so it should not call real fetch API. I understand this may be to little information but my main question is - Is react query somehow is able to skip jest mocking and call directly real query fn ?
Beta Was this translation helpful? Give feedback.
All reactions