From 2ccecb03b0f68931547e57c3545a8fa9c7aa0566 Mon Sep 17 00:00:00 2001 From: acai-alicia Date: Wed, 20 Nov 2024 19:30:29 -0500 Subject: [PATCH] Completed counter assignment with tests at 100% --- src/tests/Counter.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..34a5e6fe 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,41 @@ // import necessary react testing library helpers here +import { render } from "@testing-library/react"; +import { screen } from "@testing-library/react"; +import { fireEvent } from "@testing-library/react"; + // import the Counter component here +import Counter from "../components/Counter"; 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 counter_header = screen.getByText(/counter/i); + expect(counter_header).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { // Complete the unit test below based on the objective in the line above + const initial_count = screen.getByTestId('count'); + expect(initial_count).toHaveTextContent('0'); }); test('clicking + increments the count', () => { // Complete the unit test below based on the objective in the line above + const increment_button = screen.getByText('+'); + fireEvent.click(increment_button); + const count_value = screen.getByTestId('count'); + expect(count_value).toHaveTextContent('1'); + }); test('clicking - decrements the count', () => { // Complete the unit test below based on the objective in the line above + const decrement_button = screen.getByText('-'); + fireEvent.click(decrement_button); + const count_value = screen.getByTestId('count'); + expect(count_value).toHaveTextContent('-1'); });