Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AugustoCalaca/466880ed3ff51c17573260c1dee47a14 to your computer and use it in GitHub Desktop.
Save AugustoCalaca/466880ed3ff51c17573260c1dee47a14 to your computer and use it in GitHub Desktop.
how to properly test relay mutation with testing library
it('should call mutation properly', async () => {
// eslint-disable-next-line
const { debug, getByText, getByTestId } = render(<MyComponent />);
const customMockResolvers = {
...mockResolvers,
};
const name = 'myName';
const nameInput = getByTestId('name');
fireEvent.change(nameInput, { target: { value: name } });
const submitButton = getByText('Create').closest('button');
expect(submitButton).toBeDefined();
fireEvent.click(submitButton);
await wait(() => Environment.mock.getMostRecentOperation());
// CreateMutation
const mutationOperation = Environment.mock.getMostRecentOperation();
expect(getMutationOperationVariables(mutationOperation).input).toEqual({
name,
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment