From 39bd1784f898d5648e990f2b8b4291465f669610 Mon Sep 17 00:00:00 2001 From: kberon <73852258+kberon@users.noreply.github.com> Date: Tue, 14 Nov 2023 18:25:54 -0500 Subject: [PATCH] Updated Counter.test --- src/tests/Counter.test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..38c3e79e 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,45 @@ // import necessary react testing library helpers here +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event' + // import the Counter component here +import Counter from '../components/Counter'; +import React from 'react' + + 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 = screen.getByText(/Counter/i); + expect(counter).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { // Complete the unit test below based on the objective in the line above + const counter = screen.getByTestId('count'); + expect(counter).toHaveTextContent('0'); }); test('clicking + increments the count', () => { // Complete the unit test below based on the objective in the line above + const plusButton = screen.getByRole('button', { name: '+' }); + const counter = screen.getByTestId('count'); + + userEvent.click(plusButton); + expect(counter).toHaveTextContent('1'); }); test('clicking - decrements the count', () => { // Complete the unit test below based on the objective in the line above + const minusButton = screen.getByRole('button', { name: '-' }); + const counter = screen.getByTestId('count'); + + userEvent.click(minusButton); + expect(counter).toHaveTextContent('-1'); });