Make toEqual matcher report the difference between array elements when arrays have different length

This commit is contained in:
Gilberto Stankiewicz
2017-06-22 01:30:55 -07:00
committed by Gregg Van Hove
parent 8ad9abb19a
commit 090a6234c3
2 changed files with 103 additions and 10 deletions

View File

@@ -229,15 +229,19 @@ getJasmineRequireObj().matchersUtil = function(j$) {
// Recursively compare objects and arrays.
// Compare array lengths to determine if a deep comparison is necessary.
if (className == '[object Array]') {
size = a.length;
if (size !== b.length) {
diffBuilder.record(a, b);
return false;
}
var aLength = a.length;
var bLength = b.length;
for (i = 0; i < size; i++) {
diffBuilder.withPath('length', function() {
if (aLength !== bLength) {
diffBuilder.record(aLength, bLength);
result = false;
}
});
for (i = 0; i < aLength || i < bLength; i++) {
diffBuilder.withPath(i, function() {
result = eq(a[i], b[i], aStack, bStack, customTesters, diffBuilder) && result;
result = eq(i < aLength ? a[i] : void 0, i < bLength ? b[i] : void 0, aStack, bStack, customTesters, diffBuilder) && result;
});
}
if (!result) {