-
Notifications
You must be signed in to change notification settings - Fork 2.7k
onError is not called when using testing-library/react-hooks #6137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
i am facing a similar issue, did you manage to find a fix? |
No, we just have a skipped test with a link to this issue :( |
same issue here |
I can also reproduce this |
+1 |
Spent the last 3 hours ripping my hair off and finally found this. Any updates on this? |
any updates on this? |
any update? This is not working also, it's not triggering the
|
Does apollo-client also have retries? I dont recall that being a default configuration |
For everyone still looking for an answer. This works for me. So instead of writing:
Turn it to:
Then, and only then, your Cheers! 🥳 |
☝️ ☝️ ☝️ This may not be ideal for your test cases. You're setting the network response error when some may want to test graphql errors It results in an error like:
This makes my implementation for onError not work because I want to handle graphql errors, not network errors function onError(error?: ApolloError) {
if (!error?.graphQLErrors.length) {
return;
}
const err = error.graphQLErrors[0];
if (err.extensions?.code === "CONFLICT") {
setErrors(...);
}
} |
That's a good call out, @zebapy -- here's an example of a test that calls Since the original issue was opened several years ago and this seems to no longer be a problem (and, I might add, since |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Intended outcome:
I am writing a custom hook using Apollo React hooks, setting onError to do
console.error
if an error occurs, but otherwise only dealing with successful data. I then want to test the error state of the custom hook usingrenderHook
from@testing-library/react-hooks
andMockedProvider
. I would expectonError
to be called if an error occurs, with the same value as theerror
key in theuseQuery
result.Actual outcome:
onError
is never actually calledHow to reproduce the issue:
The following jest test fails on the last assertion on
onErrorData
Versions
The text was updated successfully, but these errors were encountered: