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: 13 additions & 10 deletions src/tests/Counter.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
// import necessary react testing library helpers here
// import the Counter component here

beforeEach(() => {
// Render the Counter component here
})
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import Counter from '../components/Counter';

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

test('clicking + increments the count', () => {
// Complete the unit test below based on the objective in the line above
const { getByTestId, getByText } = render(<Counter />);
fireEvent.click(getByText('+'));
expect(getByTestId('count')).toHaveTextContent('1');
});

test('clicking - decrements the count', () => {
// Complete the unit test below based on the objective in the line above
const { getByTestId, getByText } = render(<Counter />);
fireEvent.click(getByText('-'));
expect(getByTestId('count')).toHaveTextContent('-1');
});