Created
March 25, 2020 15:50
-
-
Save sibelius/65a36061fdab30ed2ca022dd0e416e6a to your computer and use it in GitHub Desktop.
how to properly test relay mutation with testing library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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