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 (isLoadingis true anderroris 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:
falsefrom it) and leave the call touseQueryto be as barebones as possible, the error will still not be returned.waitForis non-blocking. I would expect that awaitingawait waitFor(() => result.current.error)would wait untilresult.current.erroris 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