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

Fix "why" message for circular reference inequality #12

Merged
merged 2 commits into from
Feb 21, 2016
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
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