Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created March 25, 2020 15:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sibelius/65a36061fdab30ed2ca022dd0e416e6a to your computer and use it in GitHub Desktop.
Save sibelius/65a36061fdab30ed2ca022dd0e416e6a 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