Testing error case with React Testing Library stuck in loading phase #9582
Replies: 1 comment
-
Just fixed it. The first thing I had to do was to have an expectation inside the call to
The second thing was to fix the logic for the retry function. It was calling a function that would return Thanks for the rubber-ducking 😄. |
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.
-
Hi everyone! I'm trying to test the error-case flow for a custom hook that wraps a call to
useQuery
, but for some reason the result never gets passed the loading phase (isLoading
is true anderror
is null).This is basically the structure of my app. I'm mocking the fetcher function to return a specific error as follows:
Now, regarding the problem of the hook not moving beyond the loading phase, the most important things to highlight are:
false
from it) and leave the call touseQuery
to be as barebones as possible, the error will still not be returned.waitFor
is non-blocking. I would expect that awaitingawait waitFor(() => result.current.error)
would wait untilresult.current.error
is not null, but for some reason the test progresses no matter what, causing my assertions to fail.I've run out of ideas tbh. Hopefully someone can spot something obvious and help out! 🙏
Beta Was this translation helpful? Give feedback.
All reactions