From 836a4cf2526193817c2053ab9b71b494389ad932 Mon Sep 17 00:00:00 2001 From: yyujinparkk Date: Tue, 9 Apr 2024 17:01:27 -0400 Subject: [PATCH] passed all tests --- src/tests/Counter.test.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..52ad1f5c 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,38 @@ // import necessary react testing library helpers here +import { render, screen, fireEvent } from '@testing-library/react'; // import the Counter component here +import Counter from '../components/Counter'; // Update the path as necessary + beforeEach(() => { // Render the Counter component here + render(); }) test('renders counter message', () => { // Complete the unit test below based on the objective in the line above + const counterHeader = screen.getByText(/counter/i); + expect(counterHeader).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { // Complete the unit test below based on the objective in the line above + const countValue = screen.getByTestId('count'); + expect(countValue).toHaveTextContent('0'); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + const incrementButton = screen.getByRole('button', { name: '+' }); + fireEvent.click(incrementButton); + const countValue = screen.getByTestId('count'); + expect(countValue).toHaveTextContent('1'); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above + const incrementButton = screen.getByRole('button', { name: '+' }); // increment first to avoid negative count, assuming that's not allowed + fireEvent.click(incrementButton); // count is now 1 + const decrementButton = screen.getByRole('button', { name: '-' }); + fireEvent.click(decrementButton); // decrement back to 0 + const countValue = screen.getByTestId('count'); + expect(countValue).toHaveTextContent('0'); });