mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Assign methods should create an object when object is nullish.
This commit is contained in:
@@ -3835,7 +3835,7 @@
|
|||||||
function createAssigner(assigner) {
|
function createAssigner(assigner) {
|
||||||
return rest(function(object, sources) {
|
return rest(function(object, sources) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = object == null ? 0 : sources.length,
|
length = sources.length,
|
||||||
customizer = length > 1 ? sources[length - 1] : undefined,
|
customizer = length > 1 ? sources[length - 1] : undefined,
|
||||||
guard = length > 2 ? sources[2] : undefined;
|
guard = length > 2 ? sources[2] : undefined;
|
||||||
|
|
||||||
|
|||||||
23
test/test.js
23
test/test.js
@@ -6015,17 +6015,22 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('`_.' + methodName + '` should not error when `object` is nullish and sources are provided', function(assert) {
|
QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(2);
|
||||||
|
|
||||||
var expected = lodashStable.times(2, alwaysTrue);
|
var source = { 'a': 1 },
|
||||||
|
values = [null, undefined],
|
||||||
|
expected = lodashStable.map(values, alwaysTrue);
|
||||||
|
|
||||||
var actual = lodashStable.map([null, undefined], function(value) {
|
var actual = lodashStable.map(values, function(value) {
|
||||||
try {
|
var object = func(value, source);
|
||||||
return lodashStable.isEqual(func(value, { 'a': 1 }), {});
|
return object !== source && lodashStable.isEqual(object, source);
|
||||||
} catch (e) {
|
});
|
||||||
return false;
|
|
||||||
}
|
assert.deepEqual(actual, expected);
|
||||||
|
|
||||||
|
actual = lodashStable.map(values, function(value) {
|
||||||
|
return lodashStable.isEqual(func(value), {});
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
|
|||||||
Reference in New Issue
Block a user