_.where should perform a partial comparison of *all* objects within arrays of source. [closes #536]

This commit is contained in:
John-David Dalton
2014-04-29 09:28:56 -07:00
parent c59f8c734a
commit 5c9e4685db
2 changed files with 16 additions and 3 deletions

View File

@@ -1720,6 +1720,9 @@
break;
}
}
if (!result) {
break;
}
} else if (!(result = baseIsEqual(value[size], othValue, callback, isWhere, stackA, stackB))) {
break;
}

View File

@@ -9771,21 +9771,31 @@
deepEqual(actual, expected);
});
test('should deep compare `source` values', 1, function() {
test('should perform a deep partial comparison of `source`', 1, function() {
var collection = [{ 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 }],
expected = _.cloneDeep(collection);
expected = collection.slice();
deepEqual(_.where(collection, { 'a': { 'b': { 'c': 1 } } }), expected);
});
test('should search of arrays for values', 2, function() {
var collection = [{ 'a': [1, 2] }],
expected = _.cloneDeep(collection);
expected = collection.slice();
deepEqual(_.where(collection, { 'a': [] }), []);
deepEqual(_.where(collection, { 'a': [2] }), expected);
});
test('should perform a partial comparison of *all* objects within arrays of `source`', 1, function() {
var collection = [
{ 'a': [{ 'b': 1, 'c': 2 }, { 'b': 3, 'c': 4 }] },
{ 'a': [{ 'b': 1, 'c': 2 }, { 'b': 3, 'c': 5 }] }
];
var actual = _.where(collection, { 'a': [{ 'b': 1, 'c': 2 }, { 'b': 3, 'c': 4 }] });
deepEqual(actual, [collection[0]]);
});
test('should handle a `source` with `undefined` values', 4, function() {
var source = { 'b': undefined };
deepEqual(_.where([{ 'a': 1 }, { 'a': 1, 'b': 1 }], source), []);