From 8bd8aa3037babc03f178e4eb3c2c207b4402198b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 7 Jan 2016 21:53:35 -0800 Subject: [PATCH] Assign methods should create an object when `object` is nullish. --- lodash.js | 2 +- test/test.js | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lodash.js b/lodash.js index 8238c92ff..03907fe46 100644 --- a/lodash.js +++ b/lodash.js @@ -3835,7 +3835,7 @@ function createAssigner(assigner) { return rest(function(object, sources) { var index = -1, - length = object == null ? 0 : sources.length, + length = sources.length, customizer = length > 1 ? sources[length - 1] : undefined, guard = length > 2 ? sources[2] : undefined; diff --git a/test/test.js b/test/test.js index 23edc80ba..8dc2be54d 100644 --- a/test/test.js +++ b/test/test.js @@ -6015,17 +6015,22 @@ } }); - QUnit.test('`_.' + methodName + '` should not error when `object` is nullish and sources are provided', function(assert) { - assert.expect(1); + QUnit.test('`_.' + methodName + '` should create an object when `object` is nullish', function(assert) { + 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) { - try { - return lodashStable.isEqual(func(value, { 'a': 1 }), {}); - } catch (e) { - return false; - } + var actual = lodashStable.map(values, function(value) { + var object = func(value, source); + return object !== source && lodashStable.isEqual(object, source); + }); + + assert.deepEqual(actual, expected); + + actual = lodashStable.map(values, function(value) { + return lodashStable.isEqual(func(value), {}); }); assert.deepEqual(actual, expected);