From 6eac4a64582e103ac90bcccae81ff65a680cff5c Mon Sep 17 00:00:00 2001 From: Maxfennessy Date: Tue, 9 Apr 2024 20:52:58 -0400 Subject: [PATCH] Modified Counter test --- src/tests/Counter.test.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..62f8f153 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,25 @@ -// import necessary react testing library helpers here -// import the Counter component here - -beforeEach(() => { - // Render the Counter component here -}) +import React from 'react'; +import { render, fireEvent } from '@testing-library/react'; +import Counter from '../components/Counter'; test('renders counter message', () => { - // Complete the unit test below based on the objective in the line above + const { getByText } = render(); + expect(getByText('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 { getByTestId } = render(); + expect(getByTestId('count')).toHaveTextContent('0'); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + const { getByTestId, getByText } = render(); + fireEvent.click(getByText('+')); + expect(getByTestId('count')).toHaveTextContent('1'); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above + const { getByTestId, getByText } = render(); + fireEvent.click(getByText('-')); + expect(getByTestId('count')).toHaveTextContent('-1'); });