Skip to content
Open
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
38 changes: 30 additions & 8 deletions src/tests/Counter.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
// import necessary react testing library helpers here
// import the Counter component here
// Import necessary react testing library helpers
import { render, screen, fireEvent } from '@testing-library/react';
// Import the Counter component
import Counter from '../components/Counter';

beforeEach(() => {
// Render the Counter component here
})
// Render the Counter component before each test
render(<Counter />);
});

test('renders counter message', () => {
// Complete the unit test below based on the objective in the line above
// Verify that the Counter message is rendered
expect(screen.getByText(/Counter/i)).toBeInTheDocument();
});

test('should render initial count with value of 0', () => {
// Complete the unit test below based on the objective in the line above
// Verify that the initial count is 0
const countElement = screen.getByTestId('count');
expect(countElement.textContent).toBe('0');
});

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

fireEvent.click(incrementButton);
expect(countElement.textContent).toBe('1');

fireEvent.click(incrementButton);
expect(countElement.textContent).toBe('2');
});

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

fireEvent.click(decrementButton);
expect(countElement.textContent).toBe('-1');

fireEvent.click(decrementButton);
expect(countElement.textContent).toBe('-2');
});