From c3a5b12cd3db1a1d6c38f62d203db3c9abc1e7a8 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 6 Nov 2014 23:15:48 -0800 Subject: [PATCH] Make `_.wrap` use `_.identity` when `wrapper` is nullish. [closes #767] --- lodash.js | 1 + test/test.js | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index ef02a5ff3..5042a810d 100644 --- a/lodash.js +++ b/lodash.js @@ -6936,6 +6936,7 @@ * // => '

fred, barney, & pebbles

' */ function wrap(value, wrapper) { + wrapper = wrapper == null ? identity : wrapper; return createWrapper(wrapper, PARTIAL_FLAG, null, [value]); } diff --git a/test/test.js b/test/test.js index 2f88ff102..977da2d43 100644 --- a/test/test.js +++ b/test/test.js @@ -12458,6 +12458,18 @@ var object = { 'p': p, 'text': 'fred, barney, & pebbles' }; strictEqual(object.p(), '

fred, barney, & pebbles

'); }); + + test('should use `_.identity` when `wrapper` is nullish', 1, function() { + var values = [, null, undefined], + expected = _.map(values, _.constant('a')); + + var actual = _.map(values, function(value, index) { + var wrapped = index ? _.wrap('a', value) : _.wrap('a'); + return wrapped('b', 'c'); + }); + + deepEqual(actual, expected); + }); }()); /*--------------------------------------------------------------------------*/ @@ -13227,13 +13239,12 @@ 'rearg', 'tap', 'throttle', - 'thru', - 'wrap' + 'thru' ]; var acceptFalsey = _.difference(allMethods, rejectFalsey); - test('should accept falsey arguments', 197, function() { + test('should accept falsey arguments', 198, function() { var emptyArrays = _.map(falsey, _.constant([])), isExposed = '_' in root, oldDash = root._; @@ -13299,7 +13310,7 @@ }); }); - test('should throw a TypeError for falsey arguments', 22, function() { + test('should throw a TypeError for falsey arguments', 21, function() { _.each(rejectFalsey, function(methodName) { var expected = _.map(falsey, _.constant(true)), func = _[methodName];