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

//Written by Seth Kennedy with help from OpenAI
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 welcomeMessage = screen.getByText(/Counter/i);
expect(welcomeMessage).toBeInTheDocument();
});

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

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

test('clicking - decrements the count', () => {
// Complete the unit test below based on the objective in the line above
fireEvent.click(screen.getByText("-"));
expect(screen.getByTestId('count').textContent).toBe('-1');
});