diff --git a/test/why.js b/test/why.js index f71ca0b..ad5093a 100644 --- a/test/why.js +++ b/test/why.js @@ -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(); }); diff --git a/why.js b/why.js index 28a25fe..750af47 100644 --- a/why.js +++ b/why.js @@ -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]);