Skip to content

Commit 333d4cd

Browse files
committed
Write unit tests for App component
1 parent 6cd1b4b commit 333d4cd

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/App.test.jsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1-
import { render } from '@testing-library/react';
2-
import App from './App.jsx';
1+
import { render, screen, fireEvent } from '@testing-library/react';
2+
import App from './App';
33

4-
test('App renders without crashing', () => {
5-
const { unmount } = render(<App />);
6-
unmount();
4+
test('renders counter button', () => {
5+
render(<App />);
6+
const buttonElement = screen.getByText(/count is 0/i);
7+
expect(buttonElement).toBeInTheDocument();
8+
expect(buttonElement).toHaveTextContent(/count is 0/i);
9+
screen.debug();
10+
});
11+
12+
test('count increases on button click', () => {
13+
render(<App />);
14+
const buttonElement = screen.getByText(/count is 0/i);
15+
fireEvent.click(buttonElement);
16+
expect(buttonElement).toHaveTextContent(/count is 1/i);
17+
screen.debug();
18+
19+
fireEvent.click(buttonElement);
20+
expect(buttonElement).toHaveTextContent(/count is 2/i);
21+
screen.debug();
22+
});
23+
24+
test('renders learn react link', () => {
25+
render(<App />);
26+
const linkElement = screen.getByText(/learn react/i);
27+
expect(linkElement).toBeInTheDocument();
28+
});
29+
30+
test('renders vite docs link', () => {
31+
render(<App />);
32+
const linkElement = screen.getByText(/vite docs/i);
33+
expect(linkElement).toBeInTheDocument();
734
});

0 commit comments

Comments
 (0)