diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index c605058b..ba53d714 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2301,17 +2301,12 @@ getJasmineRequireObj().matchersUtil = function(j$) { bStack.push(b); var size = 0; // Recursively compare objects and arrays. - if (className == '[object Array]') { - // Compare array lengths to determine if a deep comparison is necessary. - size = a.length; - result = size == b.length; - if (result) { - // Deep compare the contents, ignoring non-numeric properties. - while (size--) { - if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; } - } - } - } else { + // Compare array lengths to determine if a deep comparison is necessary. + if (className == '[object Array]' && a.length !== b.length) { + result = false; + } + + if (result) { // Objects with different constructors are not equivalent, but `Object`s // from different frames are. var aCtor = a.constructor, bCtor = b.constructor; diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index f778394e..ebca6a7d 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -58,6 +58,16 @@ describe("matchersUtil", function() { expect(j$.matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false); }); + it("fails for Arrays whose contents are equivalent, but have differing properties", function() { + var one = [1,2,3], + two = [1,2,3]; + + one.foo = 'bar'; + two.foo = 'baz'; + + expect(j$.matchersUtil.equals(one, two)).toBe(false); + }); + it("passes for Errors that are the same type and have the same message", function() { expect(j$.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 260366ef..1f7a6817 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -123,17 +123,12 @@ getJasmineRequireObj().matchersUtil = function(j$) { bStack.push(b); var size = 0; // Recursively compare objects and arrays. - if (className == '[object Array]') { - // Compare array lengths to determine if a deep comparison is necessary. - size = a.length; - result = size == b.length; - if (result) { - // Deep compare the contents, ignoring non-numeric properties. - while (size--) { - if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; } - } - } - } else { + // Compare array lengths to determine if a deep comparison is necessary. + if (className == '[object Array]' && a.length !== b.length) { + result = false; + } + + if (result) { // Objects with different constructors are not equivalent, but `Object`s // from different frames are. var aCtor = a.constructor, bCtor = b.constructor;