react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

MockedProvider

Open sgentile opened this issue 4 years ago • 1 comments

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 ?

sgentile avatar Jun 10 '20 15:06 sgentile

Honestly the MockedProvider seems to not be properly documented.

  • You have to create mocks with the exact same order of properties as your query ... this part is already weird.

  • in lot of cases my queries are returning undefined values ... the mocked provider works (the no mocked response error is not throwing) => I try to find reproducible steps for this one.

MLKiiwy avatar Jun 16 '20 13:06 MLKiiwy