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
23 changes: 23 additions & 0 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, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event'

// import the Counter component here
import Counter from '../components/Counter';
import React from 'react'



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 counter = screen.getByText(/Counter/i);
expect(counter).toBeInTheDocument();
});

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

test('clicking + increments the count', () => {
// Complete the unit test below based on the objective in the line above
const plusButton = screen.getByRole('button', { name: '+' });
const counter = screen.getByTestId('count');

userEvent.click(plusButton);
expect(counter).toHaveTextContent('1');
});

test('clicking - decrements the count', () => {
// Complete the unit test below based on the objective in the line above
const minusButton = screen.getByRole('button', { name: '-' });
const counter = screen.getByTestId('count');

userEvent.click(minusButton);
expect(counter).toHaveTextContent('-1');
});