Skip to content
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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/equiv.js
Expand Up @@ -10,17 +10,15 @@ QUnit.equiv = (function() {
var parentsB = [];

function useStrictEquality( b, a ) {
if ( typeof a === "object" ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this blank line should be kept, all comments (even the jshint ones) should be preceded by a blank line.

a = a.valueOf();
}

/*jshint eqeqeq:false */
if ( b instanceof a.constructor || a instanceof b.constructor ) {

// To catch short annotation VS 'new' annotation of a declaration. e.g.:
// `var i = 1;`
// `var j = new Number(1);`
return a == b;
} else {
return a === b;
if ( typeof b === "object" ) {
b = b.valueOf();
}

return a === b;
}

function compareConstructors( a, b ) {
Expand Down
35 changes: 35 additions & 0 deletions test/main/deepEqual.js
Expand Up @@ -1581,6 +1581,41 @@ QUnit.test( "Test that must be done at the end because they extend some primitiv
}
);

QUnit.module( "Compare primitive values" );

QUnit.test( "Number", function( assert ) {
var SafeNumber = Number;

assert.ok( QUnit.equiv( new SafeNumber( 1 ), new SafeNumber( 1 ) ),
"Number objects with same values are equivalent."
);
assert.notOk( QUnit.equiv( new SafeNumber( 1 ), new SafeNumber( 2 ) ),
"Number objects with different values are not equivalent."
);
});

QUnit.test( "String", function( assert ) {
var SafeString = String;

assert.ok( QUnit.equiv( new SafeString( "foo" ), new SafeString( "foo" ) ),
"String objects with same values are equivalent."
);
assert.notOk( QUnit.equiv( new SafeString( "foo" ), new SafeString( "bar" ) ),
"String objects with different values are not equivalent."
);
});

QUnit.test( "Boolean", function( assert ) {
var SafeBoolean = Boolean;

assert.ok( QUnit.equiv( new SafeBoolean( true ), new SafeBoolean( true ) ),
"Boolean objects with same values are equivalent."
);
assert.notOk( QUnit.equiv( new SafeBoolean( true ), new SafeBoolean( false ) ),
"Boolean objects with different values are not equivalent."
);
});

QUnit.module( "equiv Maps and Sets" );

var hasES6Set = ( function() {
Expand Down