100% coverage. One obvious bug.
Coverage shows which code ran. It does not prove that assertions checked the correct behavior. A test can execute the whole function and miss the wrong answer.
Choose inputs that distinguish the intended rule from plausible mistakes. Coverage is useful evidence of execution, not a correctness certificate.
Understand it. Then fix it.
The useful part
Coverage shows which code ran. It does not prove that assertions checked the correct behavior. A test can execute the whole function and miss the wrong answer.
Make the rule explicit
Choose inputs that distinguish the intended rule from plausible mistakes. Coverage is useful evidence of execution, not a correctness certificate.
const priceAfterDiscount = (total, percent) =>
total * (1 - percent / 100);
expect(priceAfterDiscount(100, 0)).toBe(100);
expect(priceAfterDiscount(100, 20)).toBe(80);Code blocks are teaching excerpts. Keep the surrounding error handling and application requirements.
Save the code excerpts ↓Read the full transcript
My discount function has 100% line coverage. Apparently, we now owe the customer $1,900. Your only test uses zero percent off. It runs every line, but the broken formula still returns 100. Green test. Wrong confidence. So 100% means every line ran, not every case works? Exactly. Add a real discount: 20% off 100 must be 80. The test fails: minus 1,900. Percent means out of 100. Divide 20 by 100 to get 0.2. Now the formula gives 100 times 0.8: 80. Keep both tests. Coverage finds unrun code; assertions check the results you chose. Great. The code had perfect attendance. Failed math.