-
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
[V3] - Missing mocks in MockedProvider throws uncaught error #6559
Comments
As a temporary workaround, I managed to create a custom `MockLink and ignore the missing mocks errors, like so:
|
Also facing the same issue I believe. Tests were passing on v2 and now failing on v3. However, (and this might help debug the issue) |
After some more debugging it seems that this line Can't really tell what the line is doing there but removing it makes a couple of tests fail 😅 |
Can confirm this is an issue, previously we were only mocking calls that we were interested in running tests against specific responses, and ignoring other calls that might've been made by the component / page under test. Now it looks as though any unmocked call will throw an error and fail the test. @benjamn Can you clarify if this is intentional? |
As a solution you can pass an error link into the MockedProvider to handle the errors
|
As @RicardoTrindade mentioned,
Which means you can provide a function to renew the mock every time, this is how I did it:
It's weird I didn't find this mentioned in the docs. |
We are also experiencing the same issue with our application when migrating In AC2, when writing tests and using the We have hundreds of tests that relied on this behavior (either intentionally or not) - mostly because when testing a single component, the developer didn’t need to worry about mocking all of the queries being sent in children components - only a mock for the queries in the component you are directly testing was needed. I have setup a comparison (with the workaround suggested by @dheardal) as well here: Enable the workaround by following the instructions here: I'm curious if:
I'm considering adding our own implementation of the
|
Hi all - we're looking into this and will post back with an update shortly. |
We're planning on changing this behavior back to the way it was, where the error is reported through the link observable ( const mocks = // ...your mocks...
const mockLink = new MockLink(mocks);
mockLink.setOnError(error => { throw error });
// ... then call with something like
<MockedProvider link={mockLink}> |
It's working on beta 11 |
#7110 was merged to help with this. Thanks! |
I am not sure if this is a bug, or an intentional change (in #5474 ?), but the change in behavior is quite significant and caused our test suite to fail upon upgrading to v3.
Reproduction
MockedProvider
in a test environment and pass it an empty array as mocksuseQuery
hook in your testExpected result
The missing mock Error, is part of the
error
property on the return value ofuseQuery
Actual result
Uncaught error, causing the test to fail completely.
Reproduction repo
This repo: https://github.com/niekert/apollo-3-missing-mocks-behavior
npm install
npm test apollo-2.spec.js
- test passes on apollo Client 2 - missing mocks is part of return value ofuseQuery
npm test apollo-3.spec.js
- test throws uncaught error:No more mocked responses for query
Version:
@apollo/client@^3.0.0
Will happily provide more details if needed. Thank you!
The text was updated successfully, but these errors were encountered: