-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: use Object.is comparison in .strictEqual #17003
Conversation
I am a bit worried about |
Well, I do not have strong feelings about this. I am fine to close this again but it seemed like it makes sense to align both equality comparisons. So I would like to get some more opinions before closing it again. |
Is Also, you should be able to do a simple if (actual !== actual && expected !== expected) {
// actual === NaN && expected === NaN
} |
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.
LGTM if CITGM is fine with it
I guess if it’s too bad we’ll have more than enough time to revert before Node 10 :)
@@ -7,6 +7,9 @@ | |||
The `assert` module provides a simple set of assertion tests that can be used to | |||
test invariants. | |||
|
|||
For more information about the used equality comparisons see | |||
[MDN's guide on equality comparisons and sameness][mdn-equality-guide]. |
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.
Is this unrelated? Or is this doc change due to the change in the code?
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 removed the Caveats
part as there are non left but I felt like this would still be a valuable information from that part, so I moved it to the top.
@mscdex // assert.strictEqual
if (actual === expected) {
if (actual === 0 && !Object.is(actual, expected))
fail()
} else (actual === actual || expected === expected) {
fail();
}
// assert.notStrictEqual
if (actual !== expected) {
if (actual !== actual && expected !== expected)
fail()
} else (actual !== 0 || !Object.is(actual, expected)) {
fail();
} As this is semver-major though, I would rather stick to the plain |
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.
LGTM if CITGM is fine with it
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.
This deserves a documentation change warning users that "strictEqual" doesn't actually use strict equality. A YAML annotation showing which version this behavior changed is also essential, because I anticipate many many people are going to see broken tests because of this.
This aligns assert.strictEqual and assert.notStrictEqual with assert.deepStrictEqual to use the Object.is() comparison instead of strict equality.
7f868a6
to
ccfb593
Compare
@TimothyGu very good point! I updated the documentation accordingly. |
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.
Compatibility still concerns me, but the code changes LGTM.
This aligns assert.strictEqual and assert.notStrictEqual with assert.deepStrictEqual to use the Object.is() comparison instead of strict equality. PR-URL: #17003 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 493340f |
It would appear that the citgm results were not looked at. This broke the test suite for eslint.
Should we consider reverting this or is this something the eslint test suite should fix? |
Sent PR to ESLint this was due to the change in the reported error message. This is likely going to nail anyone who was grepping the text of the strictEqual or notStrictEqual output... do we think this breakage is worth it? It is going to result in some gross legacy code like https://github.com/eslint/eslint/pull/9688/files#diff-0b8e8fdd097af4021779e0f5c567281fR129 in order to support both the old and new message. |
@MylesBorins in general the changed error message might produce some more breakage but that should be limited to tests. What we could do is to use |
(More as a datapoint than anything else) This is gonna break Jest's test suite as well. Not as clean to fix as eslint due to Jest dumping the full output as a snapshot. https://github.com/facebook/jest/blob/ca1793e01eaf81497ad1985547bfa19c297881c5/integration_tests/__tests__/__snapshots__/failures.test.js.snap#L224-L252. We already need a ugly hack (jestjs/jest#4851) for the change in node 9 (not merged as we have some issues with hanging tests on node 9 (#17040)), so we'll probably just work around it for 10 as well. +1 for this change in general though, we made the same change in jest for the upcoming 22 🙂 |
At least for me, this is the information that's really useful, whether the people affected by the break agree that the new behaviour is worth having to patch their code. Given the lack of negative response, I'd say no need to revert. |
This aligns assert.strictEqual and assert.notStrictEqual with
assert.deepStrictEqual to use the Object.is() comparison instead
of strict equality.
It looked somewhat nicer with
===
but I think it makes sense to use the equality checks in both functions.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
assert