Skip to content

Commit caf841a

Browse files
docs: Update testing with disabled retries (TanStack#2460)
1 parent 9a73573 commit caf841a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/src/pages/guides/testing.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ Note that we provide a custom wrapper that builds the `QueryClient` and `QueryCl
4646

4747
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.
4848

49+
## Turn off retries
50+
51+
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:
52+
53+
```
54+
const queryClient = new QueryClient({
55+
defaultOptions: {
56+
queries: {
57+
// ✅ turns retries off
58+
retry: false,
59+
},
60+
},
61+
})
62+
const wrapper = ({ children }) => (
63+
<QueryClientProvider client={queryClient}>
64+
{children}
65+
</QueryClientProvider>
66+
);
67+
```
68+
69+
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.
70+
4971
## Testing Network Calls
5072

5173
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.

0 commit comments

Comments
 (0)