Search⌘ K

Setting Up Test Coverage

Explore how to set up and use test coverage in Jest to quantify how much JavaScript code is tested. Understand coverage metrics like statements, branches, functions, and lines. Learn how to configure coverage thresholds to ensure testing standards are met and use Jest CLI options to collect coverage data efficiently.

Introduction to test coverage

Test coverage is the quantifiable metric by which we determine how much of our code is actually being tested by our tests. Quality tests are wonderful but don't do us much good if we've left massive gaps of untested code in our application. Test coverage helps us ensure that these gaps are small or nonexistent, and it provides us the knowledge of where the gaps exist

Typically, we discuss test coverage in terms of a percentage of the total code, as well as a percentage of statements, branches, functions, and lines. Each of these has its own generated percentages that we can refer to. In this context, these terms have the following meanings:

  • Statements: This is a ...