-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useQuery not returning data when mock doesn't match query shape #8339
Comments
I have similar issue, check out my previous post: #7816 How I worked it around is I use
I think there is something wrong with |
I think the issue is similar but not the same, mine is related to mocking / testing Apollo connected components. Still I'll take a look, thanks! |
I have a reproduction listed in another issue. See #8063. |
Something useful I discovered while debugging: if you install the Apollo Client Devtools extension on chrome, select the failing query, click "run in GraphiQL", click "Load from cache", and then run the query, you will get a console warning telling you which fields are missing in your mock implementation. In my case, I was returning |
I think this is probably also causing other issues related to matching queries mocked, I was facing a couple ones using multiple queries, and different times of state, using |
Intended outcome:
Test with MockedProvider receiving mocked data successfully.
related code (minimal repro):
expected output:
test passes with useQuery response.data filled with the mock data, like this:
Actual outcome:
test fails with
data: undefined
even after loading finishes and there are no errors reported by the useQuery hook.If you add
description: whatever
to each of the mocks (schema.types[n].description), the mock works fine.My guess is that the the lack of a field asked for in the query, apparently causes some silent error, I would expect the
useQuery
function to return the mocked data, even without adescription
field.How to reproduce the issue:
codesandbox to reproduce:
https://codesandbox.io/s/sweet-bardeen-tjn9i?file=/src/MyComponent.mocks.js
steps:
MyComponent.mocks.js
(line 12 and 17).Is this a bug or an expected behaviour I am unaware of?
if so, what do you recommend to mitigate this issue when testing?
I would like to just mock the required sections of the query response for my particular test, for legibility and conciseness.
Versions
The text was updated successfully, but these errors were encountered: