From 65ad00449f587ffa13ff33705e3370b4b38efccb Mon Sep 17 00:00:00 2001 From: Ethan Date: Tue, 9 Apr 2024 22:56:32 -0400 Subject: [PATCH] added counter tests --- src/tests/Counter.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..405b4144 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,50 @@ // import necessary react testing library helpers here +import { render, fireEvent, screen } from '@testing-library/react'; // import the Counter component here +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 + + //checks that counter text is present in screen + const counterMessage = screen.getByText('Counter'); + expect(counterMessage).toBeInTheDocument(); }); test('should render initial count with value of 0', () => { // Complete the unit test below based on the objective in the line above + + //checks that counter displays as "0" on initialization + const initialValue = screen.getByText('0'); + expect(initialValue).toBeInTheDocument(); }); test('clicking + increments the count', () => { // Complete the unit test below based on the objective in the line above + + //keeps track of the value of the counter. clicks the plus/increment button + //and then checks that the text field for the counter accurately changes + const countValue = screen.getByText('0'); + const incrementButton = screen.getByText('+'); + + fireEvent.click(incrementButton); + + expect(countValue).toHaveTextContent('1'); }); test('clicking - decrements the count', () => { // Complete the unit test below based on the objective in the line above + + //does the same as above, except checks for -1 and presses decrement button + const countValue = screen.getByText('0'); + const decrementButton = screen.getByText('-'); + + fireEvent.click(decrementButton); + + expect(countValue).toHaveTextContent('-1'); });