function fee(amount, isVip) {
let f = amount * 0.02;
if (isVip) f = 0;
return f;
}
test('VIPs pay no fee', () => {
expect(fee(100, true)).toBe(0);
});
100% lines, 50% branches
The answer is 100% lines, 50% branches. Every line runs, because the condition is true and the if body is on the same line. Branch coverage counts both outcomes of the if: true and false. The non-VIP path (false) never ran. That is exactly where a fee bug could hide.
Read more