From 28a6894c2276ad9c8509fa79fa2bfec6d94d27ac Mon Sep 17 00:00:00 2001 From: Chandler Carnes Date: Tue, 9 Apr 2024 21:22:18 -0400 Subject: [PATCH] just added test cases --- src/tests/Counter.test.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..5327eccb 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,36 @@ // 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'; +let counterElement, incrementButton, decrementButton; beforeEach(() => { - // Render the Counter component here + render(); + counterElement = screen.getByTestId('count'); + incrementButton = screen.getByText('+'); + decrementButton = screen.getByText('-'); }) test('renders counter message', () => { - // Complete the unit test below based on the objective in the line above + expect(screen.getByRole('heading', { name: 'Counter' })).toBeInTheDocument(); + expect(incrementButton).toBeInTheDocument(); + expect(decrementButton).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { - // Complete the unit test below based on the objective in the line above + expect(counterElement).toHaveTextContent('0'); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + fireEvent.click(incrementButton); + expect(counterElement).toHaveTextContent('1'); + fireEvent.click(incrementButton); + expect(counterElement).toHaveTextContent('2'); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above + fireEvent.click(incrementButton); + fireEvent.click(incrementButton); + fireEvent.click(decrementButton); + expect(counterElement).toHaveTextContent('1'); });