Skip to content

Commit 468b759

Browse files
authoredSep 13, 2016
Merge pull request #60 from broofa/master
Patch for Issue #59
2 parents f8e93e4 + 731a24b commit 468b759

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎lib/assert.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,16 @@ if (typeof require !== 'undefined' && typeof process !== 'undefined') {
172172

173173
function _deepEqual(actual, expected) {
174174
// 7.1. All identical values are equivalent, as determined by ===.
175-
if (actual === expected) {
175+
if (actual === expected)
176176
return true;
177+
178+
// Convert to primitives, if supported
179+
actual = actual.valueOf ? actual.valueOf() : actual;
180+
expected = expected.valueOf ? expected.valueOf() : expected;
181+
177182
// 7.2. If the expected value is a Date object, the actual value is
178183
// equivalent if it is also a Date object that refers to the same time.
179-
} else if (actual instanceof Date && expected instanceof Date) {
184+
if (actual instanceof Date && expected instanceof Date) {
180185
return actual.getTime() === expected.getTime();
181186

182187
// 7.2.1 If the expcted value is a RegExp object, the actual value is
@@ -225,6 +230,7 @@ function isArguments (object) {
225230
function objEquiv (a, b) {
226231
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
227232
return false;
233+
228234
// an identical "prototype" property.
229235
if (a.prototype !== b.prototype) return false;
230236
//~~~I've managed to break Object.keys through screwy arguments passing.

‎test/test-base.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ exports.testSame = makeTest('same',
115115
exports.testEqual = makeTest('equal', [1, 1], [1, 2]);
116116
exports.testNotEqual = makeTest('notEqual', [1, 2], [1, 1]);
117117
exports.testDeepEqual = makeTest('deepEqual',
118-
[{one: 1}, {one: 1}], [{one: 1}, {two: 2}]
118+
[{one: 1, two: 2}, {one: 1, two: {valueOf:function() {return 2;}}}],
119+
[{one: 1, two: 2}, {two: 2}]
119120
);
120121
exports.testNotDeepEqual = makeTest('notDeepEqual',
121122
[{one: 1}, {two: 2}], [{one: 1}, {one: 1}]

0 commit comments

Comments
 (0)
Please sign in to comment.