-
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
MockedProvider is broken after an update to apollo-client 3.1.3 #6861
Comments
I dug a bit more into this and it turns out that some of the mocks have missing fields (which are irrelevant for the particular test). If I change the mocks to include all the fields requested by the query it starts working and the data property is populated. It can be really tedious to fill up all the mocks with the missing irrelevant fields, since some of our queries return lists and have dozens of fields on each item (and lots of nesting). Is there a reason why this behavior would change from apollo-client v2? It was very convenient to be able to return a mock with only the data we need for a particular test, and not have to write fixtures with the entire complex objects. |
Duplicated of #6803 |
This is so weird... I can confirm @knedev42's observation. If mocked response is not matching exactly the GraphQL, then the returned data is always undefined. This is really unpleasant way to MOCK. It's a MOCK after all! Please review and fix this issue! |
I ran into this as well when trying to upgrade from |
This was exactly my issue. Thank you, my mock data wasn't in the same shape as the query, infuriating! Thanks for the assist. |
Is there any plan to fix this issue? i understand that some bugs are not that major, but mocking a mock which is provided and currently not usable for 2 months is somehow scary for a library which is used widely in the wild. I am actually quite disappointed Edit: okay after upgrading to the mentioned beta, it actually works as intended |
Thanks for that. Spent 3 hours today trying to debug this. Hope I found this issue earlier. |
Confirmed I had the same problem with undefined |
I got bitten by this issue as well. If matching exactly the graphql field matters for tests, please at least throw an error instead of returning undefined. |
For me it is happening because of using |
Let us know if this is still a concern with |
This is great. Now working in version 3.4.8 |
I'm in the process of migrating a large codebase to the newest version of apollo-client. Most of our tests (there are hundreds of those) rely on the
MockedProvider
and they used to pass with apollo-client 2.x.x.I debugged some of them and they all exhibit the same weird behavior - the cache gets populated with the mocked response, but the
data
anderror
properties of the query areundefined
. The loading state correctly changes from "false" to "true" and then back to "false" after the cache gets populated. The network status goes from 1 (loading) to 7 (meaning the query is completed without errors). However both thedata
anderror
properties of theuseQuery
hook remainundefined
...I don't know if it matters, but I am using the
skip
property and it correctly fires off the query when it switches fromtrue
tofalse
(after all the cache also gets populated with the mocked data). The fetch policy I'm using iscache-and-network
with anextFetchPolicy: 'cache-first'
. Also the tests for error states are passing (the ones with a mock that returns anerror
instead ofdata
). The application does work outside of the tests, and that's why I suspect it's related to the MockedProvider. Also these tests used to pass 🤷Intended outcome:
To have either the
data
orerror
populated with some value after a query is completed.Actual outcome:
Both
data
anderror
are undefined after the query is completed.Versions
System:
OS: Windows 10 10.0.18363
Binaries:
Node: 10.15.1
Yarn: 1.19.0
npm: 6.4.1
Browsers:
Chrome: 84.0.4147.125
Edge: Spartan (44.18362.449.0)
npmPackages:
@apollo/client: ^3.1.3 => 3.1.3
The text was updated successfully, but these errors were encountered: