Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
lib: assert.deepEqual() fix for Error objects
Error objects have non-enumerable properties. So, unexpectedly,
assert.deepEqual(new Error('a'), new Error('b')) will not throw an
AssertionError. This commit changes that behavior.

Fixes: #3122
  • Loading branch information
Trott committed Oct 12, 2015
commit f242258a228b7d8906996cbe83690deca2ca0595
15 changes: 12 additions & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,18 @@ function objEquiv(a, b, strict) {
b = pSlice.call(b);
return _deepEqual(a, b, strict);
}
var ka = Object.keys(a),
kb = Object.keys(b),
key, i;
var ka, kb, key, i;

function _getKeys(obj) {
if (obj instanceof Error) {
return Object.getOwnPropertyNames(obj);
}
return Object.keys(obj);
}

ka = _getKeys(a);
kb = _getKeys(b);

// having the same number of owned properties (keys incorporates
// hasOwnProperty)
if (ka.length !== kb.length)
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ try {
gotError = true;
}

// https://github.com/nodejs/node/issues/3122
a.throws(makeBlock(a.deepEqual, Error('a'), Error('b')));

// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
var args = (function() { return arguments; })();
a.throws(makeBlock(a.deepEqual, [], args));
Expand Down