-
Notifications
You must be signed in to change notification settings - Fork 28.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert: handle NaN properly in deep assertions #2440
Conversation
As it is, when two container objects which have `NaN`s are asserted to be equal, it will fail. > process.version 'v3.0.0' > assert.deepEqual([NaN], [NaN]) ... AssertionError: [ NaN ] deepEqual [ NaN ] > assert.deepEqual({key: NaN}, {key: NaN}) ... This patch explicitly compares the `NaN` values with `Number.isNaN`. PR-URL: nodejs#2440
419b5d3
to
1ae3294
Compare
I'm not sure about this... NaN usually appears because of a programmer mistake. Do you have a use case where it should really be expected in a result ? |
NaN is really not equal to NaN any language, it is a part of ieee 754 standard. Changing that would be confusing. |
@targos I don't have a specific use case. But it is one of the special cases in the language and as it is we don't handle it well, IMHO. @vkurchatkin Agreed, but I believe assertion module is not necessarily just a comparison module. When I am writing a test, lets say, I am expecting a function to return an array of |
I'm -1 on this, if |
I agree with @brendanashworth . If you need to verify an array, then you could loop and |
@evanlucas What if only few of the items are NaN? |
I am still not convinced, but closing as this is -1ed. |
@thefourtheye I'd encourage you to release this on npm. |
@cjihrig Even chai had the same problem. I am trying to fix it. chaijs/chai#508 |
@thefourtheye then you end up doing something like iterating over all items and checking |
As it is, when two container objects which have
NaN
s are assertedto be equal, it will fail.
This patch explicitly compares the
NaN
values withNumber.isNaN
.PR-URL: #2440