Code coverage basics
📖 Scenario: You are working on a small Node.js project. You want to check how much of your code is tested by your tests. This helps you find parts of your code that need more testing.
🎯 Goal: Set up a simple Node.js function and a test file. Then configure a code coverage tool to measure how much of your function is tested.
📋 What You'll Learn
Create a Node.js function in a file called
math.jsCreate a test file called
math.test.js that tests the functionAdd a configuration to enable code coverage using
nycRun the tests with coverage and verify the coverage report
💡 Why This Matters
🌍 Real World
Code coverage is used in real projects to check how much code is tested. This helps developers find untested parts and improve test quality.
💼 Career
Many software jobs require writing tests and using coverage tools like nyc to ensure code quality and reliability.
Progress0 / 4 steps