1

I am trying to set the query retries to false for my tests using Jest / RTL, I was reading https://tkdodo.eu/blog/testing-react-query

It says specifying the options to:

const queryClient = new QueryClient({
   defaultOptions: {
     queries: {
       retry: false,
     },
   },
 })

await render(<QueryClientProvider client={queryClient}><DataProvider><App /></DataProvider></QueryClientProvider>)
expect(await screen.findByText(/Error fetching data/i)).toBeInTheDocument();

But this does not work as it still retries the query, however if I set the actual query to retry false, then the test passes, however I do not want to turn off retries to the actual query, just for the test only.

Any Idea's, what could be going wrong? I would have thought as per the article that setting it in the test would effect the component tree?

I have reset the handler also for MSW, to get a 500 error response.

Sole
  • 3,100
  • 14
  • 58
  • 112
  • Please provide a [mvce](https://stackoverflow.com/help/minimal-reproducible-example) – Lin Du Jul 14 '22 at 10:01
  • 1
    how does your query look like? If you have `retry: true` or something on the query directly, this will overwrite the defaults set by the queryClient. – TkDodo Jul 15 '22 at 09:40
  • So on the actual query not the test, if I set to false, then the test passes, but it looks the the `queryClient` for the test is not being picked up or working? – Sole Jul 15 '22 at 12:15
  • Just odd API. These settings are for defaults, they do not override the settings in the actual query. – Izhaki Apr 18 '23 at 13:54

0 Answers0