apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.85k stars 790 forks source link

MockedProvider #4018

Open sgentile opened 4 years ago

sgentile commented 4 years ago

I've been writing tests and running into quite a bit of an issue with the "No more mocked responses for the query" error.

Reading this article https://medium.com/@emmanuellaaninye/errors-when-testing-apollo-graphql-in-react-no-more-mocked-responses-for-the-query-fe1b54756491 highlights all the issues around testing.

I'm not sure I quite get the design behind this MockedProvider. No where in the documentation does it cover how to use it. Actually based on documentation it would seem this is rather straightforward: (1) provide your mock input (2) provide your mock output. Done.

That said then, why are we needing to 'pass multiple identical' mocks in. Why are we needing to match a specific 'property order'. And why isn't the failed message writing out something like 'you passed 'xyz' we expected 'abc' ?

this is it right here: https://www.apollographql.com/docs/react/api/react-testing/#mockedprovider

it says "doesn't send out network requests to your API, but rather allows you to specify the exact response payload for a given request". If that is the case, and based on that example, why would I ever get a "No more mocked responses for the query" error ? And why isn't that mentioned here ?

MLKiiwy commented 4 years ago

Honestly the MockedProvider seems to not be properly documented.