MockedProvider - mutation errors are not passed to the component
See original GitHub issueHi, I have been facing a problem mocking data with MockedProvider. With queries all works as expected, when I mock success and errors, the problem comes with mutations, success are ok but when I try to mock an error it is not passed to my component in the render function, instead an Error is thrown.
Test:
const mocks = [
{
request: {
query: MY_MUTATION,
variables: {
userId: 'error'
},
},
error: new Error('boom!')
}
];
it('my test that should pass', () => {
const wrapper = mount(
<MockedProvider mocks={mocks}>
<MyComponent ... />
</MockedProvider>
);
...
Component:
<Mutation mutation={MY_MUTATION} >
{(cancelMandate, {loading, error}) => (
...
When I run the test it just throw the exception but in a live environment it is passed to the component!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Testing React components - Apollo GraphQL Docs
Using MockedProvider and associated APIs · The MockedProvider component · Testing the "loading" and "success" states · Testing error states · Testing mutations....
Read more >apollo's MockedProvider doesn't warn clearly about missing ...
When this happens, MockedProvided returns a NetworkError to the component. However in the test suite, no warning is displayed. This is ...
Read more >Errors when testing Apollo GraphQL in React — “No more ...
When testing graphql APIs the recommended practice according to React-Apollo is to use a MockedProvider to wrap your component.
Read more >Testing Apollo: How to test if a mutation was called with ...
Support for testing components that use Apollo is very good for the most part. But still, some situations are confusing and not well…...
Read more >Jest & Apollo Client: testing mutation error states
I wrote a test suite for this component, all of which worked correctly, until I got to the stage when I was testing...
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
We managed to get around it using errorPolicy if anyone else gets stuck:
I see the same, but in queries as well. Both of these:
and
Simply throw an error in Jest and fail the test. Using: