Mutation.isPending does not reset to false after the update finishes in my test #7792
Unanswered
binhtran04
asked this question in
Q&A
Replies: 0 comments
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.
-
Hi,
I already searched through the discussions but didn't find the answer.
I'm going to describe my issue below.
In my component, I use useMutation to update the data, and in onError I toast an error message. Furthermove, I use
mutation.isPending
to disable/enable the save button.in my test, I use
msw
to mock the network. I want to test the error case, to show the correct toast message, and re-enable the save button afterwards.In my mock when I use
await delay()
, themutation.isPending
initially correctly switches fromfalse
totrue
and then it shows the toast error correctly. But after that, it fails to switch back tofalse
after the toastError is called. In other words, the save button is supposed to be re-enabled at the end of the test, but it stays disabled.The expected behaviour of the
mutation.isPending
state would be false -> true -> falsebut the real behaviour is false -> true
However, this only happens in my tests. In the real software, I can verify that the
isPending
state correctly changes.How can I properly test mutation isPending state? Thank you in advance for your help.
"@tanstack/react-query": "^5.30.0",
"vite": "^5.3.1",
"vitest": "^1.6.0",
"msw": "^2.3.0",
Beta Was this translation helpful? Give feedback.
All reactions