React Unit Testing
React-Testing-Library |
Official Website
The React Testing Library is a very light-weight solution for testing React components. is a testing utility tool that’s built to test the actual DOM tree rendered by React on the browser. The goal of the library is to help you write tests that resemble how a user would use your application.
example :
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/some_text/i);
expect(linkElement).toBeInTheDocument();
});Command
npm run test:unitFor interactive mode:
npm run test:watchFor Test coverage:
npm run test:coverageLast updated on