From 6b924e2448f393e0c363bc4d9e613d1c3f79c4ac Mon Sep 17 00:00:00 2001 From: lucyjin3 <73535572+lucyjin3@users.noreply.github.com> Date: Tue, 9 Apr 2024 18:44:20 -0400 Subject: [PATCH] counter-assignment --- src/tests/Counter.test.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..48630949 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,40 @@ -// import necessary react testing library helpers here -// import the Counter component here +import React from 'react'; +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 counterElement = screen.getByText('Counter'); + expect(counterElement).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { - // Complete the unit test below based on the objective in the line above + const countElement = screen.getByTestId('count'); + expect(countElement).toHaveTextContent('0'); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + const incrementButton = screen.getByText('+'); + const countElement = screen.getByTestId('count'); + + fireEvent.click(incrementButton); + expect(countElement).toHaveTextContent('1'); + + fireEvent.click(incrementButton); + expect(countElement).toHaveTextContent('2'); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above + const decrementButton = screen.getByText('-'); + const countElement = screen.getByTestId('count'); + + fireEvent.click(decrementButton); + expect(countElement).toHaveTextContent('-1'); + + fireEvent.click(decrementButton); + expect(countElement).toHaveTextContent('-2'); });