Description
A js quirk that can bite you is the fact that zeroes can be negative signed. Signs are ignored in this case when comparing numbers by equality, so -0 == 0, and even -0 === 0. However, -0 isn't 0, so Object.is
returns false when comparing those values.
The thing is that the strictEqual function inside the assert module has a very special treatment for zeroes, where it prefers to call Object.is
:
function innerDeepEqual(val1, val2, strict, memos) {
// All identical values are equivalent, as determined by ===.
if (val1 === val2) {
if (val1 !== 0)
return true;
return strict ? Object.is(val1, val2) : true;
}
Since the legacy (non-strict) mode is deprecated, one can no longer easily assert that a statement will have a result of 0 without knowing whether or not that statement will result in a negative zero.
So I suggest to either remove the special treatment for negative zeroes (which might be a breaking change) or enable legacy mode.
The current work around is moving from
assert.equal(fn(), 0)
to
assert(fn() === 0)
which results in worse error messages.