MockedProvider gives incorrect error message with undefined variables
See original GitHub issueIntended outcome:
MockedProvider error message correctly describes GraphQL request missing a mock when no matching mock present
Actual outcome:
No more mocked responses for the query: query GetIssues($a: ID, $b: ID, $c: String!, $d: String!) {
getIssues(a: $a, b $b, c: $c, d: $d) {
id
name
}
}
, variables: {"a":"123","c":"456","d":"789"}
Note that the query I am sending actually has b: undefined
in the variables, and that’s why the mock (which did not include b
in the variables) did not match, but MockedProvider
did not tell me this.
How to reproduce the issue:
Set up a mock for a query that takes an optional variable, pass undefined to it in your code, but omit it from variables
in your mock. It will fail to match, but the error message will not mention it.
Versions
System:
OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
Binaries:
Node: 13.8.0 - ~/n/bin/node
Yarn: 1.22.0 - ~/duboce-labs/pganalyze/node_modules/.bin/yarn
npm: 6.14.4 - ~/n/bin/npm
Browsers:
Chrome: 84.0.4147.89
Firefox: 78.0.2
npmPackages:
@apollo/client: ^3.0.2 => 3.0.2
apollo: ^2.23.0 => 2.23.0
npmGlobalPackages:
apollo: 2.18.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:5 (3 by maintainers)
Top Results From Across the Web
apollo's MockedProvider doesn't warn clearly about missing ...
The idea is to give the MockedProvider a custom apollo link. By default, it uses MockLink initialized with the given mocks.
Read more >Debugging Apollo GraphQL MockedProvider - Swarmia
When seeing this error, we know that Apollo MockProvider received query getDogParent from a component but no matching mock was found. The phrase ......
Read more >Testing React components - Apollo GraphQL Docs
The MockedProvider component. Every test for a React component that uses Apollo Client must make Apollo Client available on React's context.
Read more >How to fix Apollo's MockedProvider returning empty objects for ...
<MockedProvider addTypename={false} mocks={MOCKS}> ... but your response provides it, it fails silently, and you get an empty response.
Read more >Gotchas using React Apollo MockProvider | by Tomoaki Imai
To get a more precise error message, let's add InMemoryCache as props of MockProvider. <MockedProvider mocks={mocks} addTypename cache={
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think #7108 fixed this.
I’ve offered a fix for the error message, and some failing tests for the mock matching behavior itself in #8285
Can we reopen?
To be completely honest with you, we did not get around to improving our testing/mocking utilities in AC3, but they are badly in need of an update, and this is a great example of a shortcoming in how the mocking utilities match queries/variables. Thanks for opening this issue!