Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,16 @@ assert.deepEqual = function deepEqual(actual, expected, message) {

function _deepEqual(actual, expected) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
if (actual === expected)
return true;

// Convert to primitives, if supported
actual = actual.valueOf ? actual.valueOf() : actual;
expected = expected.valueOf ? expected.valueOf() : expected;

// 7.2. If the expected value is a Date object, the actual value is
// equivalent if it is also a Date object that refers to the same time.
} else if (actual instanceof Date && expected instanceof Date) {
if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();

// 7.3. Other pairs that do not both pass typeof value == "object",
Expand Down Expand Up @@ -192,6 +197,7 @@ function isArguments (object) {
function objEquiv (a, b) {
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
return false;

// an identical "prototype" property.
if (a.prototype !== b.prototype) return false;
//~~~I've managed to break Object.keys through screwy arguments passing.
Expand Down
3 changes: 2 additions & 1 deletion test/test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ exports.testSame = makeTest('same',
exports.testEqual = makeTest('equal', [1, 1], [1, 2]);
exports.testNotEqual = makeTest('notEqual', [1, 2], [1, 1]);
exports.testDeepEqual = makeTest('deepEqual',
[{one: 1}, {one: 1}], [{one: 1}, {two: 2}]
[{one: 1, two: 2}, {one: 1, two: {valueOf:function() {return 2;}}}],
[{one: 1, two: 2}, {two: 2}]
);
exports.testNotDeepEqual = makeTest('notDeepEqual',
[{one: 1}, {two: 2}], [{one: 1}, {one: 1}]
Expand Down