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: Support compare primitive objects in deepEqual #905
Conversation
QUnit.test( "Compare primitive objects", function( assert ) { | ||
var SafeNumber = Number, | ||
SafeString = String, | ||
SafeBoolean = Boolean; |
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.
why saving these references? Does not look necessary.
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.
@leobalter
For lint validation. like it link
:)
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.
Oops, makes sense.
We should fix the code style here, that's relatively new on the code style, but we should declare all the variables with a new var statement.
var SafeNumber = Number;
var SafeString = String;
var SafeBoolean = Boolean;
I know I commented on several details, but this is a great work adding a great value to QUnit.equiv. I'm looking forward to merge this PR. Thanks, @mixed! |
@leobalter |
@@ -1581,6 +1581,39 @@ QUnit.test( "Test that must be done at the end because they extend some primitiv | |||
} | |||
); | |||
|
|||
QUnit.test( "Compare Number values", function( assert ) { |
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.
@mixed: would you create a single module on the top of these tests called "Compare primitive values"?
Example:
QUnit.module( "Compare primitive values" );
We're close! |
|
||
// Compare same constructor. | ||
return a.toString() == b.toString(); |
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 this could be generalized and simplified a bit further, to something like
if ( typeof a === "object" ) {
a = a.valueOf();
}
if ( typeof b === "object" ) {
b = b.valueOf();
}
return a === b;
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.
@gibson042
Thank you. I think of it again. I think this don't have to check type. Could you please explain to me more detail about check type? And How about think below logic?
function useStrictEquality( b, a ) {
if ( b instanceof a.constructor || a instanceof b.constructor ) {
return a.valueOf() === b.valueOf();
} else {
return a === b;
}
}
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.
Well, there are two issues. First, and most importantly, we should probably have an automatic return true
in a separate guaranteed
function for null
, undefined
, and nan
"types". Having cleared those out of the way, there would be a few options for detecting wrapped primitives, and I like typeof object
because it strikes me as the most semantic. And separate from all of that, it's just nice to see a single return
with uniform comparison logic.
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.
Thank you. :)
I have misunderstood it. but I get it now. I think that check 'constructor' and check 'typeof' before I understand your comment.
Good comments. I updating it soon.
@gibson042 can we merge this? |
I increased test coverage a little and restored an explanatory comment, but yes! 😀 |
This is awesome! thanks, @mixed and @gibson042 |
Ref #895