Skip to content

Commit

Permalink
Merge pull request #12 from jmm/circ-ref-message
Browse files Browse the repository at this point in the history
[Fix] fix "why" message for circular reference inequality
  • Loading branch information
ljharb committed Feb 21, 2016
2 parents adc9c0a + 6b9e478 commit bf1d4a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions test/why.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,5 +628,21 @@ test('circular references', function (t) {
'two objects with different circular references are not equal'
);

var e = {};
var f = {};
e.e = e;
f.e = null;
t.equal(
isEqualWhy(e, f),
'first argument has a circular reference at key "e"; second does not',
'two objects without corresponding circular references are not equal'
);

t.equal(
isEqualWhy(f, e),
'second argument has a circular reference at key "e"; first does not',
'two objects without corresponding circular references are not equal'
);

t.end();
});
2 changes: 1 addition & 1 deletion why.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ module.exports = function whyNotEqual(value, other) {
otherKeyIsRecursive = other[key] && other[key][key] === other;
if (valueKeyIsRecursive !== otherKeyIsRecursive) {
if (valueKeyIsRecursive) { return 'first argument has a circular reference at key "' + key + '"; second does not'; }
return 'second argument has a circular reference at key "' + key + '"; second does not';
return 'second argument has a circular reference at key "' + key + '"; first does not';
}
if (!valueKeyIsRecursive && !otherKeyIsRecursive) {
keyWhy = whyNotEqual(value[key], other[key]);
Expand Down

0 comments on commit bf1d4a4

Please sign in to comment.