mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Ensure _.iteratee clones sources for "_.matchesProperty" shorthand.
This commit is contained in:
@@ -13150,9 +13150,7 @@
|
||||
* // => [{ 'user': 'fred', 'age': 40 }]
|
||||
*/
|
||||
function iteratee(func) {
|
||||
return (isObjectLike(func) && !isArray(func))
|
||||
? matches(func)
|
||||
: baseIteratee(func);
|
||||
return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
33
test/test.js
33
test/test.js
@@ -10623,7 +10623,7 @@
|
||||
assert.strictEqual(matches({ 'b': 2 }), false);
|
||||
});
|
||||
|
||||
QUnit.test('should not change behavior if `source` is modified', function(assert) {
|
||||
QUnit.test('should not change `_.matches` behavior if `source` is modified', function(assert) {
|
||||
assert.expect(9);
|
||||
|
||||
var sources = [
|
||||
@@ -10652,7 +10652,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is a number or string and a value is provided', function(assert) {
|
||||
QUnit.test('should return an iteratee created by `_.matchesProperty` when `func` is an array', function(assert) {
|
||||
assert.expect(3);
|
||||
|
||||
var array = ['a', undefined],
|
||||
@@ -10676,6 +10676,35 @@
|
||||
assert.strictEqual(matches(object), true);
|
||||
});
|
||||
|
||||
QUnit.test('should not change `_.matchesProperty` behavior if `source` is modified', function(assert) {
|
||||
assert.expect(9);
|
||||
|
||||
var sources = [
|
||||
{ 'a': { 'b': 2, 'c': 3 } },
|
||||
{ 'a': 1, 'b': 2 },
|
||||
{ 'a': 1 }
|
||||
];
|
||||
|
||||
lodashStable.each(sources, function(source, index) {
|
||||
var object = { 'a': lodashStable.cloneDeep(source) },
|
||||
matches = _.iteratee(['a', source]);
|
||||
|
||||
assert.strictEqual(matches(object), true);
|
||||
|
||||
if (index) {
|
||||
source.a = 2;
|
||||
source.b = 1;
|
||||
source.c = 3;
|
||||
} else {
|
||||
source.a.b = 1;
|
||||
source.a.c = 2;
|
||||
source.a.d = 3;
|
||||
}
|
||||
assert.strictEqual(matches(object), true);
|
||||
assert.strictEqual(matches({ 'a': source }), false);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should return an iteratee created by `_.property` when `func` is a number or string', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user