Skip to content

Instantly share code, notes, and snippets.

@kalpeshsingh
Created August 7, 2021 02:10
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 kalpeshsingh/90e1ddee47764f1f3cc028a8e7edd638 to your computer and use it in GitHub Desktop.
Save kalpeshsingh/90e1ddee47764f1f3cc028a8e7edd638 to your computer and use it in GitHub Desktop.
AAA Pattern in Writing Test Cases
describe('test cases for Button component', () => {
it('should call callback fn when onPress is fired', () => {
/** Arrange **/
const handleClick = jest.fn()
const { getByTestId, toJSON } = render(
<Button onPress={handleClick}>
<Text>Test Button</Text>
</Button>
)
/** Act: perform the actual work of the test **/
const buttonElement = getByTestId('touchableElement')
fireEvent.press(buttonElement)
/** Assert – verify the result **/
expect(handleClick).toHaveBeenCalledTimes(1)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment