Skip to content

toBeOdd fails on negative odd numbers (false pass with .not) #191

Open

Description

@fefi95

Priority: P1

Context

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

  1. self-assigned this
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions