Created
August 7, 2021 02:10
-
-
Save kalpeshsingh/90e1ddee47764f1f3cc028a8e7edd638 to your computer and use it in GitHub Desktop.
AAA Pattern in Writing Test Cases
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
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