From 738c10fd43b232673fc1ef107f35e263245ea25e Mon Sep 17 00:00:00 2001 From: Ben Christel Date: Mon, 18 Jul 2016 16:48:00 -0700 Subject: [PATCH] Make `toEqual` pass for arrays with equivalent properties - Fixes a bug caused by accidental use of a closure variable --- spec/core/matchers/matchersUtilSpec.js | 10 ++++++++++ src/core/matchers/matchersUtil.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 3f0deac1..d6ab504e 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -75,6 +75,16 @@ describe("matchersUtil", function() { expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(false); }); + it("passes for Arrays with equivalent contents and properties", function() { + var one = [1,2,3], + two = [1,2,3]; + + one.foo = 'bar'; + two.foo = 'bar'; + + expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(true); + }); + it("passes for Errors that are the same type and have the same message", function() { expect(jasmineUnderTest.matchersUtil.equals(new Error("foo"), new Error("foo"))).toBe(true); }); diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 50b376c8..ef92c1d4 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -225,7 +225,7 @@ getJasmineRequireObj().matchersUtil = function(j$) { var extraKeys = []; for (var i in allKeys) { if (!allKeys[i].match(/^[0-9]+$/)) { - extraKeys.push(key); + extraKeys.push(allKeys[i]); } }