From 9d66b6e3430e58af298a1539041de16dacc643fc Mon Sep 17 00:00:00 2001 From: Valentina Aguilar Date: Sun, 16 Apr 2023 23:22:41 -0400 Subject: [PATCH] Updated Counter.test.js --- .idea/.gitignore | 8 +++++ .idea/counter-assignment.iml | 8 +++++ .idea/inspectionProfiles/Project_Default.xml | 6 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ src/tests/Counter.test.js | 37 ++++++++++++++++---- 6 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/counter-assignment.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/counter-assignment.iml b/.idea/counter-assignment.iml new file mode 100644 index 0000000..bc2cd87 --- /dev/null +++ b/.idea/counter-assignment.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..03d9549 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dac7415 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18a..c575ffe 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,47 @@ // import necessary react testing library helpers here +import { render, screen } from '@testing-library/react'; // import the Counter component here +import Counter from '../components/Counter'; +import userEvent from "@testing-library/user-event"; beforeEach(() => { - // Render the Counter component here + // Render the Counter component here + render (); }) test('renders counter message', () => { - // Complete the unit test below based on the objective in the line above + // Complete the unit test below based on the objective in the line above + const counterMessage = screen.getByText(/Counter/i); + 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 + // Complete the unit test below based on the objective in the line above + const initialCount = screen.getByTestId('count'); + expect(initialCount.textContent).toBe('0'); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + // Complete the unit test below based on the objective in the line above + const incrementButton = screen.getByText(/\+/i); + const countDisplay = screen.getByTestId('count'); + + userEvent.click(incrementButton); + expect(countDisplay.textContent).toBe('1'); + + userEvent.click(incrementButton); + expect(countDisplay.textContent).toBe('2'); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above -}); + // Complete the unit test below based on the objective in the line above + const decrementButton = screen.getByText(/-/i); + const countDisplay = screen.getByTestId('count'); + + userEvent.click(decrementButton); + expect(countDisplay.textContent).toBe('-1'); + + userEvent.click(decrementButton); + expect(countDisplay.textContent).toBe('-2'); +}); \ No newline at end of file