function discount(total: number, isMember: boolean) {
return isMember && total > 100 ? total * 0.9 : total;
}
test("member discount", () => {
expect(discount(200, true)).toBe(180);
});
Branch coverage
Branch coverage reveals the gap. It tracks both outcomes of the condition. The 'no discount' path never runs, so branch coverage shows only half the branches covered. The tempting line and statement coverage options are wrong. The whole function is one line and one statement, so those metrics are already at 100%. Function coverage is also 100%, because the function was called.
Read more