Skip to content

Commit 21e70d1

Browse files
committed
write test cases
1 parent 769c3d4 commit 21e70d1

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
.slingshot/

src/test/App.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from "react";
2+
import { render, screen, fireEvent } from "@testing-library/react";
3+
import "@testing-library/jest-dom/extend-expect";
4+
import App from "../components/app.jsx"; // Adjust the import path as necessary
5+
6+
test("rendersAppWithoutCrashing", () => {
7+
render(<App />);
8+
expect(screen.getByText(/Welcome to the App/i)).toBeInTheDocument();
9+
});
10+
11+
test("displaysInitialStateCorrectly", () => {
12+
render(<App />);
13+
expect(screen.getByText(/Initial State/i)).toBeInTheDocument();
14+
});
15+
16+
test("handlesButtonClickEvent", () => {
17+
render(<App />);
18+
const button = screen.getByRole("button", { name: /Click Me/i });
19+
fireEvent.click(button);
20+
expect(screen.getByText(/Button Clicked/i)).toBeInTheDocument();
21+
});
22+
23+
test("rendersErrorMessageOnInvalidInput", () => {
24+
render(<App />);
25+
const input = screen.getByLabelText(/Input/i);
26+
fireEvent.change(input, { target: { value: "invalid" } });
27+
expect(screen.getByText(/Error: Invalid Input/i)).toBeInTheDocument();
28+
});
29+
30+
test("updatesStateOnValidInput", () => {
31+
render(<App />);
32+
const input = screen.getByLabelText(/Input/i);
33+
fireEvent.change(input, { target: { value: "valid" } });
34+
expect(screen.getByText(/State Updated/i)).toBeInTheDocument();
35+
});

0 commit comments

Comments
 (0)