Difference between statement and line coverage in jest
Asked Answered
A

2

34

Can anyone explains me the difference between line coverage and statement coverage in jest. When I ran my coverage report I got a different line coverage percentage compared to statement. enter image description here

Anglesey answered 21/1, 2020 at 17:59 Comment(1)
what is the unit coverage in this output? is this the number of lines covered in this repository which is 45.45 % here?Sarraceniaceous
P
61

if you have a line of code that says var x= 10; console.log(x); that's one line and 2 statements.

Statement coverage has each statement in the program been executed.

Line coverage has each executable line in the source file been executed.

Patella answered 21/1, 2020 at 18:5 Comment(1)
This still doesn't make sense. The programming language is free-form.Centaury
M
0

There can be two statements in one line, but only one statement gets executed

if ({} + [] == 0) || exit(1)

exit(1) will never occur, because the first statement is always true, and the || operator 'short circuits' the line as soon as the first true is found.

Malvasia answered 7/6 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.