0
0
Node.jsframework~20 mins

Code coverage basics in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Code Coverage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Understanding coverage output summary
Given the following test coverage summary output from a Node.js project, what is the percentage of statements covered?
Node.js
Statements   : 80.0% ( 40/50 )
Branches     : 75.0% ( 15/20 )
Functions    : 90.0% ( 9/10 )
Lines       : 85.0% ( 34/40 )
A80%
B75%
C90%
D85%
Attempts:
2 left
💡 Hint
Look for the line labeled 'Statements' and check the percentage.
component_behavior
intermediate
1:30remaining
Effect of missing tests on coverage
If a function in your Node.js code is never called by any test, what will the coverage report show for that function?
AThe coverage report will show an error.
BThe function will show 100% coverage by default.
CThe function will show 0% coverage.
DThe function will be excluded from the coverage report.
Attempts:
2 left
💡 Hint
Think about what happens if code is never executed during tests.
📝 Syntax
advanced
2:00remaining
Correct way to instrument code for coverage
Which of the following commands correctly instruments a Node.js project using nyc for coverage before running tests?
Amocha --coverage
Bnyc --reporter=lcov mocha
Cnode --coverage test.js
Dnpm run coverage
Attempts:
2 left
💡 Hint
nyc is a popular coverage tool that wraps test commands.
🔧 Debug
advanced
2:00remaining
Diagnosing missing coverage data
You ran your tests with coverage, but the report shows 0% coverage for all files. What is the most likely cause?
AThe source files are excluded in the coverage configuration.
BThe coverage tool was not installed.
CThe coverage report was generated before running tests.
DThe tests did not execute any code because they failed to run.
Attempts:
2 left
💡 Hint
Verify if tests ran successfully and executed the source code.
🧠 Conceptual
expert
2:30remaining
Interpreting branch coverage results
A coverage report shows 75% branch coverage. What does this mean about your tests?
A75% of all possible paths through conditional branches were executed during tests.
B75% of the code lines were executed during tests.
C75% of functions were called during tests.
D75% of statements were executed during tests.
Attempts:
2 left
💡 Hint
Branch coverage relates to conditional paths, not lines or functions.