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
Binary file added Wantman, Trent - Automated Unit Testing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 18 additions & 8 deletions src/tests/Counter.test.js
Original file line number Diff line number Diff line change
@@ -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(<Counter />);
});

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 count = screen.getByTestId('count');
expect(count).toHaveTextContent('0');
});

test('clicking + increments the count', () => {
// Complete the unit test below based on the objective in the line above
const incrementButton = screen.getByText('+');
const count = screen.getByTestId('count');

fireEvent.click(incrementButton);
expect(count).toHaveTextContent('1');
});

test('clicking - decrements the count', () => {
// Complete the unit test below based on the objective in the line above
const decrementButton = screen.getByText('-');
const count = screen.getByTestId('count');

fireEvent.click(decrementButton);
expect(count).toHaveTextContent('-1');
});