From caf841ae933a2733b6a1ac5a865b556331b3eec4 Mon Sep 17 00:00:00 2001 From: Mauricio Soares Date: Fri, 16 Jul 2021 05:54:35 -0300 Subject: [PATCH] docs: Update testing with disabled retries (#2460) --- docs/src/pages/guides/testing.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/src/pages/guides/testing.md b/docs/src/pages/guides/testing.md index 9f95e5dbb5..488704de9e 100644 --- a/docs/src/pages/guides/testing.md +++ b/docs/src/pages/guides/testing.md @@ -46,6 +46,28 @@ Note that we provide a custom wrapper that builds the `QueryClient` and `QueryCl It is possible to write this wrapper only once, but if so we need to ensure that the `QueryClient` gets cleared before every test, and that tests don't run in parallel otherwise one test will influence the results of others. +## Turn off retries + +The library defaults to three retries with exponential backoff, which means that your tests are likely to timeout if you want to test an erroneous query. The easiest way to turn retries off is via the QueryClientProvider. Let's extend the above example: + +``` +const queryClient = new QueryClient({ + defaultOptions: { + queries: { + // ✅ turns retries off + retry: false, + }, + }, +}) +const wrapper = ({ children }) => ( + + {children} + +); +``` + +This will set the defaults for all queries in the component tree to "no retries". It is important to know that this will only work if your actual useQuery has no explicit retries set. If you have a query that wants 5 retries, this will still take precedence, because defaults are only taken as a fallback. + ## Testing Network Calls The primary use for React Query is to cache network requests, so it's important that we can test our code is making the correct network requests in the first place.