-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
assert: use same value equal for deepStrictEqual NaN #15036
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -466,6 +466,7 @@ assertOnlyDeepEqual( | |
| assertDeepAndStrictEqual(m3, m4); | ||
| } | ||
|
|
||
| // Handle sparse arrays | ||
| assertDeepAndStrictEqual([1, , , 3], [1, , , 3]); | ||
| assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); | ||
|
|
||
|
|
@@ -481,4 +482,11 @@ assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); | |
| assertOnlyDeepEqual(err1, {}, assert.AssertionError); | ||
| } | ||
|
|
||
| // Handle NaN | ||
| assert.throws(() => { assert.deepEqual(NaN, NaN); }, assert.AssertionError); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is the bad part about the wording with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually that is IMHO a great idea, create a better named superset assertion. That would also make this change semver-minor.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is absolutely not the right thing to do. And as I tried to explain earlier
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that That's why I think breaking away
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The deepEqual and deepStrictEqual functions have much more then just the "basic" comparison and therefore do not correspond to these properly. I would love if that would be the only distinction because in that case |
||
| assert.doesNotThrow(() => { assert.deepStrictEqual(NaN, NaN); }); | ||
| assert.doesNotThrow(() => { assert.deepStrictEqual({ a: NaN }, { a: NaN }); }); | ||
| assert.doesNotThrow( | ||
| () => { assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]); }); | ||
|
|
||
| /* eslint-enable */ | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
typeof actual === 'number'can be removed,Number.isNaN(actual)is sufficient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct but it is faster for all other types to check for number first and if it is a number it is not a real penalty because that check is super fast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it makes sense to do the same for
expectedthen?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but I feel like that is overdoing it as it would only apply for the case where
Number.isNaN(actual), especially as I would expectexpectedto also be NaN in that case more often then not being of type number.