DEV Community

Vijay Thirugnanam
Vijay Thirugnanam

Posted on

React component to measure code coverage of QA

To measure code coverage, first instrument the build using babel-plugin-istanbul.

Then in your React application, add React components from npm package to display code coverage results.

npm install istanbul-coverage-display
Enter fullscreen mode Exit fullscreen mode

Add the summary component in all pages. It gets added at fixed position in the bottom left corner of the screen.

import { CoverageSummary } from 'istanbul-coverage-display'
Enter fullscreen mode Exit fullscreen mode

Optionally, Add the detail component in a specific route in the application, say /coverage.

import { CoverageDetail } from 'istanbul-coverage-display'
Enter fullscreen mode Exit fullscreen mode

By providing the onNavigate prop in CoverageSummary, we can navigate to the route having the CoverageDetail component.

<CoverageSummary onNavigate={navigateToDetail} />
Enter fullscreen mode Exit fullscreen mode

For more information, why we need this for QA testing, check out my blog.

There is also a demo for this component.

Top comments (0)