Skip to content

Instantly share code, notes, and snippets.

@nottyo
Last active August 12, 2022 05:56
Show Gist options
  • Select an option

  • Save nottyo/c3de28dce1eb9fb3cc1fa7f4f9d0681d to your computer and use it in GitHub Desktop.

Select an option

Save nottyo/c3de28dce1eb9fb3cc1fa7f4f9d0681d to your computer and use it in GitHub Desktop.
RTL Practice - Parent.test
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Parent from './Parent';
describe('Parent Integration Test', () => {
it('emit click increased event from child component', () => {
// when
render(<Parent />);
const increaseButton = screen.getByTestId('increase-click');
userEvent.click(increaseButton);
// then
const counter = screen.getByTestId('counter');
expect(counter).toHaveTextContent('1');
});
it('emit click decreased event from child component', () => {
// when
render(<Parent />);
const increaseButton = screen.getByTestId('increase-click');
userEvent.click(increaseButton);
const decreaseButton = screen.getByTestId('decrease-click');
userEvent.click(decreaseButton);
// then
const counter = screen.getByTestId('counter');
expect(counter).toHaveTextContent('0');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment