0
0
Node.jsframework~5 mins

Code coverage basics in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is code coverage?
Code coverage measures how much of your code is tested by automated tests. It shows which parts of the code ran during testing.
Click to reveal answer
beginner
Name three common types of code coverage.
1. Line coverage: checks if each line of code ran.<br>2. Branch coverage: checks if each decision path ran.<br>3. Function coverage: checks if each function was called.
Click to reveal answer
intermediate
Why is 100% code coverage not always necessary?
Because some code is hard to test or not critical. Also, high coverage doesn't guarantee no bugs, but it helps find many issues.
Click to reveal answer
beginner
How do you generate code coverage reports in Node.js?
You can use tools like 'nyc' (Istanbul) with your test runner. Run tests with coverage enabled to see which code ran.
Click to reveal answer
beginner
What does a coverage report typically show?
It shows percentages of lines, branches, and functions covered. It highlights uncovered code to improve tests.
Click to reveal answer
What does line coverage measure?
AIf the code compiles without errors
BIf each function was called
CIf each line of code was executed during tests
DIf each branch decision was tested
Which tool is commonly used in Node.js for code coverage?
AJest
Bnyc (Istanbul)
CMocha
DExpress
Why might 100% code coverage be unrealistic?
ABecause some code is unreachable or hard to test
BBecause tests are not important
CBecause coverage tools are inaccurate
DBecause code coverage slows down the app
What does branch coverage check?
AIf each function was called
BIf the code is formatted correctly
CIf the code runs without errors
DIf each decision path (like if/else) was tested
What is the main benefit of using code coverage?
ATo find untested parts of code and improve test quality
BTo make the code run faster
CTo reduce the size of the code
DTo automatically fix bugs
Explain what code coverage is and why it is useful in testing Node.js applications.
Think about how you check if your tests run all parts of your code.
You got /4 concepts.
    Describe how you would set up code coverage reporting in a Node.js project.
    Consider the tools and commands you use to see which code your tests cover.
    You got /4 concepts.