ReactJs — React Testing with Jest and React Testing Library
Testing ensures your components work correctly. Jest is a testing framework, and React Testing Library provides utilities to test React components effectively.
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import Button from './Button';
test('renders button with correct label', () => {
render(<Button label="Click Me" onClick={() => {}} />);
expect(screen.getByText('Click Me')).toBeInTheDocument();
});