Also check custom properties on Arrays when computing equality
[Finishes #50616649]
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user