From 935c18aeb6d7d8bb703c59f64dc5ae8e652e193d Mon Sep 17 00:00:00 2001 From: shudgit Date: Sat, 8 Apr 2023 19:13:42 -0400 Subject: [PATCH] Added Counter Tests --- src/tests/Counter.test.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18a..cea17d3 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,30 @@ -// import necessary react testing library helpers here -// import the Counter component here +import { render, screen, fireEvent } from '@testing-library/react'; +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 message = screen.getByText(/Counter/i); + expect(message).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { - // Complete the unit test below based on the objective in the line above + const count = screen.getByTestId("count"); + expect(count).toHaveTextContent("0"); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + const incrementButton = screen.getByText("+"); + fireEvent.click(incrementButton); + const count = screen.getByTestId("count"); + expect(count).toHaveTextContent("1"); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above + const decrementButton = screen.getByText("-"); + fireEvent.click(decrementButton); + const count = screen.getByTestId("count"); + expect(count).toHaveTextContent("-1"); });