Skip to content

Commit 3838db7

Browse files
authored
docs: Add a note on suppressing console errors in tests (TanStack#2567)
1 parent bac853f commit 3838db7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/src/pages/guides/testing.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ const wrapper = ({ children }) => (
6868

6969
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.
7070

71+
## Turn off network error logging
72+
73+
When testing we want to supress network errors being logged to the console.
74+
To do this, we can use `react-query`'s `setLogger()` function.
75+
76+
```ts
77+
// as part of your test setup
78+
import { setLogger } from 'react-query'
79+
80+
setLogger({
81+
log: console.log,
82+
warn: console.warn,
83+
// ✅ no more errors on the console
84+
error: () => {},
85+
})
86+
```
87+
7188
## Testing Network Calls
7289

7390
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)