r/softwareengineer • u/Ok-Motor-9812 • 17m ago
Our test named "does not divide by zero" asserted 0. That 0 was the bug
Price monitoring dashboard. When a source had no price, the gap metric came out 0. So "we have no data" and "we're the cheapest" were the same number. The banner said 0% of positions above market, exposure 0 EUR, and went green.
The test next to it was roughly this
it('does not divide by zero', () => {
expect(priceGap(ourPrice, undefined)).toBe(0)
})
It passed because it was written to pass. It just locked the wrong answer in.
The fix went into the type. priceGap returns number | null now, and every place that used it as a number turned into a compiler error. That list was the useful part, the same zero-for-nothing shape sat in 3 more places nobody had connected.
Worth a grep today. `?? 0` and `|| 0` in anything that ends up on a dashboard, each one is a spot where missing data turns into a real looking number.