-
-
Save AugustoCalaca/466880ed3ff51c17573260c1dee47a14 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