You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
toBeOdd fails on negative odd numbers (false pass with .not) #191
JS % keeps the sign of the left operand, so -13 % 2 === -1. The check % 2 === 1 in packages/core/src/lib/NumberAssertion.ts:237 therefore treats every negative odd number as not odd:
expect(-13).toBeOdd() throws, even though it's the method's own JSDoc example (:220).
expect(-13).not.toBeOdd()passes. That's a false pass: users' tests go green on wrong code.
The tests only use positive values, which is why 98% coverage never caught this. Reproduced against the built dist.
Do
Use assertWhen: Math.abs(this.actual % 2) === 1.
Check how toBeEven handles -0, NaN, Infinity and non-integers (1.5). Decide the behaviour and document it.
Add tests for negative numbers and non-integers to packages/core/test/lib/NumberAssertion.test.ts (the .toBeOdd block is at line 162).
Commit as fix(core): toBeOdd fails on negative odd numbers.
Done when
The new tests fail on main and pass on the branch.
Source: code audit of stackbuilders/assertive-ts at e81a614 (2026-10-13) plus open Vanta/Dependabot findings.
Activity