jest mock client execute mutation fails assertion
See original GitHub issue@JoviDeCroock @kitten expect(mockClient.executeMutation).toBeCalledTimes(1); /// gives 0
may be I am doing something wrong. but can you guys guide me
sample code
const apiClient: any = {
executeMutation: jest.fn(() =>
fromValue({
fetching: true,
data: {
login: {
token: '',
},
},
}),
),
};
const { getByTestId } = render(
<Provider value={apiClient}>
<Login />
</Provider>,
);
const submitEl = getByTestId('submit');
await act(async () => {
const userNameEl = getByTestId('email');
const passwordEl = getByTestId('password');
fireEvent.change(userNameEl, {
target: {
value: 'username',
},
});
fireEvent.change(passwordEl, {
target: {
value: 'password',
},
});
await fireEvent.click(submitEl);
});
expect(mockClient.executeMutation).toBeCalledTimes(1);
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
jest mock client execute mutation fails assertion #868 - GitHub
Hey,. How does the component look? I assume it works when you're using this in the browser/your relevant environment? Is it possible there's ......
Read more >Testing React components - Apollo GraphQL Docs
This article describes best practices for testing React components that use Apollo Client. The examples below use Jest and React Testing Library, ...
Read more >Testing Apollo: How to test if a mutation was called with ...
If you assign a mock function here you can simply assert whether or not that function was called. But enough talking, let's have...
Read more >Mock Apollo Client in tests (#68) · Issues - GitLab
For checking query result, we assert it as a data property and for mutations we're able to mock resolved value. You can find...
Read more >Testing Apollo Mutation graphql errors - Stack Overflow
When mutation fails, react-apollo throws an error if no onError prop is provided to Mutation component (source code here).
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 Free
Top 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
There is nothing about that second argument in the testing docs, so I can see why that would cause confusion. It currently demonstrates:
Perhaps the docs should be updated?
@chiragprodsmiths looks like you’re just missing the second argument for
executeMutation
here: https://github.com/FormidableLabs/urql/blob/062c1359a7ccd41044d2eb963ab0da5629143cc5/packages/core/src/client.ts#L343-L344 (Note the red, {}
at the end of Jest’s Received output.