liveBook · Manning

Code coverage

As explained in Functional Programming in JavaScript

The proportion of a program’s executable code that is exercised by a test suite or other execution run.

Code coverage measures how much executable code a test suite exercises. It reveals untested areas, especially overlooked error-handling paths, but coverage alone does not prove quality. section 6.5

Measure JavaScript coverage by:

  • Loading the source files. section 6.5
  • Instrumenting the code with tracker lines that record statement execution. section 6.5
  • Connecting the test runner to a report showing executed lines and coverage percentages. section 6.5

A coverage result

A QUnit test that exercises only the valid path of an imperative showStudent function executes 12 of 15 lines, producing 80% coverage. A corresponding functional version reaches 100% for its testable business logic.

How Functional Programming in JavaScript covers it

How deep it goes
Defines statement coverage, path traversal, and instrumentation phases, but stops short of treating coverage as a quality guarantee.
Examples
Uses QUnit tests, Blanket.js reports, showStudent variants, and contrasting 80% and 100% line-coverage results.
What it assumes
Assumes JavaScript functions and unit tests, while introducing coverage measurement and instrumentation.
What you can do after
Diagnose untested code paths and add tests for missed branches, including error-handling behavior.
How it connects
Connects unit testing with control flow, boundary conditions, error handling, functional programming, and imperative programming.

Also explained in

Compare how 14 books explain code coverage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.