-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
I was using AVA to test some math stuff the other day and noticed that I needed to use t.deepEqual()
to test for NaN
. If the ===
test was swapped out for Object.is()
in assert.js
it would be able to correctly handle NaN
being 'equal' to NaN
without having to resort to deepEqual
.
The loss we get with switching to Object.is
as far as MDN says is that +0
and -0
are not longer treated as equal. That's actually probably okay, as they are 'more different' than two NaN
s are, and certainly the NaN
problem is far more common than "why doesn't it think my two zeroes are the same?" it could be argued that, during a test, you may well wish to know if you are getting two different zeroes.
Checking the package.json
it says that the 'engine' must be node >= 4
, and Node.js 4 does indeed support Object.is()
according to the ES compatibility table.
All that said, the same MDN article linked above, further down, says that maybe using Object.is()
could introduce more confusion (though it'd be interesting to know if power assert can correctly give meaningful output in a diff of +0
and -0
, as that would probably be what this hinges on) so may best be avoided. If it is decided that this is the case, I thinking adding the specific isNaN
checks to is
in assert.js
would still be really helpful as, arguably, NaN
is (in the sense of t.is
) NaN
, it's just not "strictly 100% guaranteed to be actually the exact same type of NaN
value as the NaN
you passed into the t.is
function", which is not what people want when they say t.is
.