From c08dea0cef76bb042edc5e6ad799d20148758456 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Sun, 23 Feb 2014 16:53:17 -0500 Subject: [PATCH] Enforce `arguments` constraint reflexively If an `arguments` object is not considered `eql` to an array, then the inverse should also hold true. --- index.js | 9 +++++---- test/expect.js | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index b1e921d..3cd3cb6 100644 --- a/index.js +++ b/index.js @@ -929,10 +929,11 @@ if (a.prototype !== b.prototype) return false; //~~~I've managed to break Object.keys through screwy arguments passing. // Converting to array solves the problem. - if (isArguments(a)) { - if (!isArguments(b)) { - return false; - } + var aIsArgs = isArguments(a), + bIsArgs = isArguments(b); + if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) + return false; + if (aIsArgs) { a = pSlice.call(a); b = pSlice.call(b); return expect.eql(a, b); diff --git a/test/expect.js b/test/expect.js index 7b24cdf..c372408 100644 --- a/test/expect.js +++ b/test/expect.js @@ -312,6 +312,14 @@ describe('expect', function () { expect('4').to.eql(4); expect(/a/gmi).to.eql(/a/mig); + err(function() { + expect([]).to.eql(arguments); + }, 'expected [] to sort of equal {}'); + + err(function() { + expect(arguments).to.eql([]); + }, 'expected {} to sort of equal []'); + err(function () { expect(4).to.eql(3); }, 'expected 4 to sort of equal 3');