Skip to content

Commit

Permalink
Write unit tests for App component
Browse files Browse the repository at this point in the history
  • Loading branch information
SafdarJamal committed Jul 26, 2023
1 parent 6cd1b4b commit 333d4cd
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import { render } from '@testing-library/react';
import App from './App.jsx';
import { render, screen, fireEvent } from '@testing-library/react';
import App from './App';

test('App renders without crashing', () => {
const { unmount } = render(<App />);
unmount();
test('renders counter button', () => {
render(<App />);
const buttonElement = screen.getByText(/count is 0/i);
expect(buttonElement).toBeInTheDocument();
expect(buttonElement).toHaveTextContent(/count is 0/i);
screen.debug();
});

test('count increases on button click', () => {
render(<App />);
const buttonElement = screen.getByText(/count is 0/i);
fireEvent.click(buttonElement);
expect(buttonElement).toHaveTextContent(/count is 1/i);
screen.debug();

fireEvent.click(buttonElement);
expect(buttonElement).toHaveTextContent(/count is 2/i);
screen.debug();
});

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

test('renders vite docs link', () => {
render(<App />);
const linkElement = screen.getByText(/vite docs/i);
expect(linkElement).toBeInTheDocument();
});

0 comments on commit 333d4cd

Please sign in to comment.