Unit test for useMutation hook 's can't be mocked to run onError callback #6696
Unanswered
ducle-infotrack
asked this question in
Q&A
Replies: 2 comments
-
Please don't mock the whole query package - just mock your |
Beta Was this translation helpful? Give feedback.
0 replies
-
as sugested you should mock your api.post to throw an error, and you easily can point yout assert to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
Description
When running the unit test for the
useMuation
hook,The
mocked mutation
function is expected to be throw error andonError
callback is executed, but it appears to not be called at all.Your minimal, reproducible example
VScode
Steps to reproduce
Steps to Reproduce
Run the unit test for
useMutation
Observe the test results.
Expected behavior
The
mockError
function should be called with the following arguments:How often does this bug happen?
Screenshots or Videos
No response
Platform
Node.js version: 18.18.2
NPM/Yarn version: 9.8.1
React version: 18
Testing library: Jest with Enzyme
Operating System: Ubuntu
Tanstack Query adapter
react-query
TanStack Query version
5.14.2
TypeScript version
5.3.3
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions