DEV Community

Vijay Thirugnanam
Vijay Thirugnanam

Posted on

3 3

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay