Skip to content

Instantly share code, notes, and snippets.

@rzymek
Last active February 4, 2021 19:22
Show Gist options
  • Save rzymek/0147116a9daa17583cf5e28cb0eb8539 to your computer and use it in GitHub Desktop.
Save rzymek/0147116a9daa17583cf5e28cb0eb8539 to your computer and use it in GitHub Desktop.
it('should calculate on click', () => {
// given:
render(<Calculator/>);
// when
typeIn('expression', '6 * 7');
clickOn('calculate');
// then
expect(textOf('result')).toBe('42');
}
);
const typeIn = (selector: string, value: string) =>
userEvent.type(screen.getByTestId(selector), value);
const clickOn = (selector: string) => userEvent.click(screen.getByTestId(selector));
const textOf = (selector: string) => screen.getByTestId(selector).textContent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment