Is it possible to test different types of errors in an apollo-client mock?
I want to test a component first using a graphql error and then test it again with a regular error.
Here's the mockError I made, it contains a graphql error and a regular error. I want to test them both in the same test, without having to make two separate mocks. The following does not work, since it's only rendering the regular error and not the graphql error.
test('should show error UI', async () => {
const errorMock = [
{
request: {
query: STATUS_QUERY,
},
result: {
errors: [new GraphQLError("here's a graphql error")],
},
error: new Error("here's a regular error"),
},
];
const { getByLabelText } = render(
<MockedProvider mocks={errorMock} addTypename={false}>
<Status />
</MockedProvider>
);
await waitFor(() => new Promise((resolve) => setTimeout(resolve, 0)));
expect(getByLabelText('error message')).toHaveTextContent(
"Error: here's a graphql error"
);
await waitFor(() => new Promise((resolve) => setTimeout(resolve, 0)));
expect(getByLabelText('error message')).toHaveTextContent(
"Error: here's a regular error"
);
});
Unsure if I'm thinking about this correctly or if I'm missing the point. What would be the normal way of doing this?