mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
_.where should perform a partial comparison of *all* objects within arrays of source. [closes #536]
This commit is contained in:
@@ -1720,6 +1720,9 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
} else if (!(result = baseIsEqual(value[size], othValue, callback, isWhere, stackA, stackB))) {
|
||||
break;
|
||||
}
|
||||
|
||||
16
test/test.js
16
test/test.js
@@ -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), []);
|
||||
|
||||
Reference in New Issue
Block a user