-
Notifications
You must be signed in to change notification settings - Fork 783
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
Support differentiating -0 and +0 (sameValue assertion) #1010
Comments
🤘 |
@leobalter would the eventual goal here be to replace one or both of our current equality checks with these assertions? I'm concerned about overwhelming users with options that are very similar. |
I want to approximate the API to the JS specs and test262. Maybe the I also have to admit I see them as good candidates for lodash as well. One good argument for them is the lack of support for precisely comparing To check NaN values, the global isNaN is unreliable and Number.isNaN is On Tuesday, June 28, 2016, Trent Willis [email protected] wrote:
|
Okay, makes sense. I understood the logic for having them, but I wanted to clarify the long term goals |
I think having both For NaN, I can see an edge case where the current Worth noting here is that QUnit.test('example', assert => {
assert.strictEqual(NaN, NaN, 'fails');
assert.deepEqual(NaN, NaN, 'passes');
assert.deepEqual({ a: NaN }, { a: NaN }, 'passes');
}); And Node.js' I think that strikes a fairly good balance. For inline expressions of primitive values, we'd stick with strict equality for better parity and intuition of how JavaScript generally works. For recursive comparing of more complex structures, we'd use the sameValue logic for each individual value, thus supporting the matching NaN (as we do today) and differentiating of Would that leave any use cases uncovered? We'd land this in 3.0 to avoid breaking tests in the event 0/-1 equality is relied upon in deepEqual calls today. |
ECMAScript has two internal abstractions to compare values called sameValue and sameValueZero.
They are different than
==
and===
as they return true for NaN values and compare-0
and+0
.Based on my experience with test262, and considering some personal goals I have for QUnit (still seeking funding for it) I believe it's fair to ship assertions that does the same comparisons, while I believe it's dangerous to simply modify
strictEqual
.Object.is
returns the exact result forsameValue
, but that's an ES6 feature and not available on supported browsers. The results are the same as===
but with special checks for NaN and bit precision zeros.Here goes some data on how they would work:
equal
strictEqual
deepEqual
propEqual
_.isEqual
sameValue
sameValueZero
The following code can provide some results, as it uses lodash's isEqual as well:
cc @jdalton
The text was updated successfully, but these errors were encountered: