Skip to content

Jest and nock: My existing interceptors seem to seep across test suits #2307

Answered by peterMuriuki
peterMuriuki asked this question in Q&A
Discussion options

You must be logged in to vote

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

defaultOptions: {
    queries: {
      retry: false,
      cacheTime: 0,
    },
  },

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by peterMuriuki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant