diff --git a/src/tests/Counter.test.js b/src/tests/Counter.test.js index 36cc18aa..0779fb7d 100644 --- a/src/tests/Counter.test.js +++ b/src/tests/Counter.test.js @@ -1,22 +1,32 @@ -// import necessary react testing library helpers here -// import the Counter component here +import React from "react"; +import { render, screen, fireEvent } from "@testing-library/react"; +import Counter from "../components/Counter.js"; beforeEach(() => { - // Render the Counter component here -}) + render(); +}); -test('renders counter message', () => { - // Complete the unit test below based on the objective in the line above +test("renders counter message", () => { + 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 +test("should render initial count with value of 0", () => { + const initialCount = screen.getByTestId("count"); + expect(initialCount.textContent).toBe("0"); }); -test('clicking + increments the count', () => { - // Complete the unit test below based on the objective in the line above +test("clicking + increments the count", () => { + const addButton = screen.getByText("+"); + fireEvent.click(addButton); + const countElement = screen.getByTestId("count"); + expect(countElement.textContent).toBe("1"); }); -test('clicking - decrements the count', () => { - // Complete the unit test below based on the objective in the line above +test("clicking - decrements the count", () => { + const subtractButton = screen.getByText("-"); + fireEvent.click(subtractButton); + const countElement = screen.getByTestId("count"); + expect(countElement.textContent).toBe("-1"); }); +