Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 55 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -47,5 +46,8 @@
"statements": 100
}
}
},
"devDependencies": {
"@testing-library/react": "^14.3.0"
}
}
29 changes: 26 additions & 3 deletions src/tests/Counter.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
// 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
})

test('renders counter message', () => {
// Complete the unit test below based on the objective in the line above
render(<Counter />);
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
const { getByTestId } = render(<Counter />);
const initialValue = Number(getByTestId("count").textContent);
expect(initialValue).toEqual(0);
});

test('clicking + increments the count', () => {
// Complete the unit test below based on the objective in the line above
const { getByTestId, getByRole } = render(<Counter />);
const incrementBtn = getByRole("button", {name: "+"});

//now click the button
fireEvent.click(incrementBtn);

//now test to see that our count value incremented
const countValue = Number(getByTestId("count").textContent);
expect(countValue).toEqual(1);
});

test('clicking - decrements the count', () => {
// Complete the unit test below based on the objective in the line above
const { getByTestId, getByRole } = render(<Counter />);
const incrementBtn = getByRole("button", {name: "-"});

//now click the button
fireEvent.click(incrementBtn);

//now test to see that our count value incremented
const countValue = Number(getByTestId("count").textContent);
expect(countValue).toEqual(-1);
});