apollo-client: Breaking change from 3.0.2 to 3.1.0 [ MockedProvider ]
Intended outcome: Be able to mock a query using MockProvider
import { MockedProvider } from '@apollo/client/testing';
import { GET_TEACHERS_AND_ADMINS_OF_MY_DISTRICT_QUERY } from '../queries';
const mocks = [
{
request: {
query: GET_TEACHERS_AND_ADMINS_OF_MY_DISTRICT_QUERY,
},
result: {
loading: false,
error: null,
data: {
teachersAndAdminsOfMyDistrict: [
{
[...]
...
<MockedProvider mocks={mocks} addTypename={false}>
<ComponentThatUsesTheQuery />
</MockedProvider>
Actual outcome:
After updating to 3.1.0 tests broke with:
No more mocked responses for the query: {
teachersAndAdminsOfMyDistrict {
[...]
How to reproduce the issue: Described in the first section but if more info is needed I can add here.
Versions
System:
OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
Binaries:
Node: 10.19.0 - /usr/bin/node
npm: 6.14.4 - /usr/bin/npm
Browsers:
Chrome: 84.0.4147.105
Firefox: 79.0
npmPackages:
@apollo/client: ^3.1.0 => 3.1.0
apollo-upload-client: ^14.1.0 => 14.1.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 16
- Comments: 22 (3 by maintainers)
Commits related to this issue
- Update @wry/equality to improve undefined property handling. See https://github.com/benjamn/wryware/pull/21 for explanation and motivation. Should help with #6771, #6803, #6688, #6378, and #7081, and... — committed to apollographql/apollo-client by benjamn 4 years ago
- Update @wry/equality to improve undefined property handling. (#7108) See https://github.com/benjamn/wryware/pull/21 for explanation and motivation. Should help with #6771, #6803, #6688, #6378, and #... — committed to apollographql/apollo-client by benjamn 4 years ago
I’ve resolved this with my post on this one
@tyagow as a work around, you can mock
useQuery
like so:+1
We’re also experiencing this issue
I was having this issue on any 3.x.x version (my mocks have correct variables + __typenames and all that junk, this seemed like a legitimate bug with MockedProvider), upgrading to @apollo/client@3.3.0-beta.9 did NOT fix it for me, but upgrading to @apollo/client@3.3.0-beta.16 DID fix it for me.
edit: just wanted to say that this didn’t fix everything, still had some tests that were failing that definitely should pass (spent hours checking typenames + variables, 100% sure things are accurate). We had the most trouble with components that had 2 different queries running in the same file as well as queries with empty variables), it always got confused. ended up doing this in our jest
basically just forcing no-cache for testing purposes
This behavior should be fixed/improved in
@apollo/client@3.3.0-beta.9
(just published to npm), thanks to #7108. Please give it another try after updating!The current apollo-client release is 3.3.5, and this seems to be fixed now.
Get this error -
No more mocked responses for the query: mutation
. Seems likeMockedProvider
broken or poorly documented.I am actually unable to get
MockedProvider
working at all on any 3.x version of@apollo/client
.Leaving out this, the loading state is always true. With it the component is able to log out
loading: true
and thenloading: false
.The assertion fails, data is always undefined in the component even when
loading: false
from theuseQuery
.I am running multiple queries, but the tests pass when I set the fetchPolicy to ‘no-cache’. I’m currently using the workaround @btferus5 suggested
I found the issue to be the same as @Markus-ipse
The change in behavior appears to have been introduced here, by switching to a different deep equal function: https://github.com/apollographql/apollo-client/commit/2593f8f62fbe87e5a3eebb8b44e0f5482a75c3f7#diff-fab0a81f7f7c1e746fd7f86a7a1458c9 and https://github.com/apollographql/apollo-client/commit/26849a804a1be65071818285c9c31de8a8e4fb13 (cc: @benjamn)
The previous
isEqual
implementation ignoredundefined
object properties. Unfortunately, we were relying on that behavior so hundreds of our tests are now failing in 3.1.x.