From 99acf43d63dd9abf10c4f8e66e32b62b8a563c7a Mon Sep 17 00:00:00 2001 From: sethMKennedy <62225478+sethMKennedy@users.noreply.github.com> Date: Tue, 9 Apr 2024 23:37:33 -0400 Subject: [PATCH] added tests for counter --- src/tests/Counter.test.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..eaa3f010 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,31 @@ // import necessary react testing library helpers here // import the Counter component here +//Written by Seth Kennedy with help from OpenAI +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 welcomeMessage = screen.getByText(/Counter/i); + expect(welcomeMessage).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { - // Complete the unit test below based on the objective in the line above + const initialCount = screen.getByText(/0/i); + expect(initialCount).toBeInTheDocument(); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + fireEvent.click(screen.getByText('+')); + expect(screen.getByTestId('count').textContent).toBe('1'); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above + fireEvent.click(screen.getByText("-")); + expect(screen.getByTestId('count').textContent).toBe('-1'); });