React Unit Testing
React-Testing-Library |
Official Website (opens in a new tab)
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:unit
For interactive mode:
npm run test:watch
For Test coverage:
npm run test:coverage