Simple but often overlooked tech nuggets

Simple but often overlooked tech nuggets

Jest's types of test coverage

Duc Trinh's photo
Duc Trinh
·May 30, 2022·

1 min read

Play this article

Have you ever ran Jest tests and got these following outputs, wondering which type of coverage to use?

image.png

Below is a definition for each type:

  • Function coverage: Has each function (or subroutine) in the program been called?
  • Statement coverage: Has each statement in the program been executed?
  • Branch coverage: Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? For example, given an if statement, have both the true and false branches been executed? Another way of saying this is, has every edge in the program been executed?
  • Line coverage: has each executable line in the source file been executed?

Ref: krishankantsinghal.medium.com/how-to-read-t..