Jest and nock: My existing interceptors seem to seep across test suits #2307
-
I am trying to return the different results from the same endpoint within the same test file. I know from the documentation that interceptors are removed once matched, expect for when they are persisted. In my tests, it seems like for a single test file I can only mock an endpoint once, trying to "re-mock" it in another test suite with different response does not work, it only returns the response from the first mock instance for all other scopes of the same ednpoint. Using I am not sure if there is something wrong with my test setup, and would appreciate some help on this. I have created a small repo to reproduce the issue here |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
My problem was with how I had setup the configs for react-query during testing. Apparently React query caches data for 5 minutes by default. My mocked failed request would result in an error, but React query was giving me back both the stale data and the error. My ui code disregards errors if there is data, so my tests were expecting an error which they were not seeing. I fixed this by tweaking the the query client config to have a cache time of 0
|
Beta Was this translation helpful? Give feedback.
My problem was with how I had setup the configs for react-query during testing. Apparently React query caches data for 5 minutes by default. My mocked failed request would result in an error, but React query was giving me back both the stale data and the error. My ui code disregards errors if there is data, so my tests were expecting an error which they were not seeing. I fixed this by tweaking the the query client config to have a cache time of 0