diff --git a/package-lock.json b/package-lock.json index 5926b041..62c60148 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "counter", "version": "0.1.0", "dependencies": { - "@testing-library/jest-dom": "^5.16.5", + "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "react": "^18.2.0", @@ -3494,9 +3494,9 @@ } }, "node_modules/@testing-library/jest-dom": { - "version": "5.16.5", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.16.5.tgz", - "integrity": "sha512-N5ixQ2qKpi5OLYfwQmUb/5mSV9LneAcaUfp32pn4yCnpb8r/Yz0pXFPck21dIicKmi+ta5WRAknkZCfA8refMA==", + "version": "5.17.0", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.17.0.tgz", + "integrity": "sha512-ynmNeT7asXyH3aSVv4vvX4Rb+0qjOhdNHnO/3vuZNqPmhDpV/+rCSGwQ7bLcmU2cJ4dvoheIO85LQj0IbJHEtg==", "dependencies": { "@adobe/css-tools": "^4.0.1", "@babel/runtime": "^7.9.2", @@ -19323,9 +19323,9 @@ } }, "@testing-library/jest-dom": { - "version": "5.16.5", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.16.5.tgz", - "integrity": "sha512-N5ixQ2qKpi5OLYfwQmUb/5mSV9LneAcaUfp32pn4yCnpb8r/Yz0pXFPck21dIicKmi+ta5WRAknkZCfA8refMA==", + "version": "5.17.0", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.17.0.tgz", + "integrity": "sha512-ynmNeT7asXyH3aSVv4vvX4Rb+0qjOhdNHnO/3vuZNqPmhDpV/+rCSGwQ7bLcmU2cJ4dvoheIO85LQj0IbJHEtg==", "requires": { "@adobe/css-tools": "^4.0.1", "@babel/runtime": "^7.9.2", diff --git a/package.json b/package.json index a40f5f6c..d70acb93 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "@testing-library/jest-dom": "^5.16.5", + "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "react": "^18.2.0", diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..a63c8992 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,32 @@ -// import necessary react testing library helpers here -// import the Counter component here +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 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 + const initialCount = screen.getByText(/0/); + expect(initialCount).toBeInTheDocument(); }); test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above + const incrementButton = screen.getByText('+'); + fireEvent.click(incrementButton); + + const updatedCount = screen.getByText('1'); + expect(updatedCount).toBeInTheDocument(); }); test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above + const decrementButton = screen.getByText('-'); + fireEvent.click(decrementButton); + + const updatedCount = screen.getByText('-1'); + expect(updatedCount).toBeInTheDocument(); });