Test fails using onError callback #4110
Replies: 4 comments 4 replies
-
@diogo-simao To avoid errors aborting your execution, you should silence it during the test: If you are using React Query V3: import { setLogger } from 'react-query'
setLogger({
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => {},
}) If you are using React Query V4: const queryClient = new QueryClient({
logger: {
log: console.log,
warn: console.warn,
// ✅ no more errors on the console
error: () => {},
}
}) More info here: |
Beta Was this translation helpful? Give feedback.
-
I have the same issue and the proposed solution does not work for me either. The error is no longer being logged, but the test is still short-circuited and the onError callback is not being executed. Can anyone shed more light on this? |
Beta Was this translation helpful? Give feedback.
-
I also have the same issue and the proposed solution does not work for me either. |
Beta Was this translation helpful? Give feedback.
-
the callbacks on queries are deprecated in v4 and have been removed in v5, so I'll not look into this because the only course of action is to remove the callback, which means you don't need to test it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Im using Jest and MSW to test a component that uses useQuery.
Here is my current test:
The problem is that my test is failing due a unhandled promise, rejected by MSW and not been handled by the onError:
If my queryFn is wrapped by a try/catch block, everything passes:
Is there anything that can be made?
Your minimal, reproducible example
/
Steps to reproduce
Expected behavior
I was expecting that onError somehow should handle the promise rejection.
How often does this bug happen?
No response
Screenshots or Videos
No response
Platform
Linux
react-query version
3.34
TypeScript version
3.9.3
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions