From 76f668dddd9c6611ce5e88b5e75198d4d48b4bae Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 24 Mar 2014 09:14:28 -0700 Subject: [PATCH] Add tests for `_.map`, `_.invoke`, `_.shuffle`, and `_.sortBy` for treating numbers as empty. --- test/test.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index d93017088..ceab4a6ce 100644 --- a/test/test.js +++ b/test/test.js @@ -3732,6 +3732,10 @@ deepEqual(_.invoke(object, 'toFixed', 1), ['1.0', '2.0', '3.0']); }); + test('should treat number values for `collection` as empty', 1, function() { + deepEqual(_.invoke(1), []); + }); + test('should work with `null` or `undefined` elements', 1, function() { var array = ['a', null, undefined, 'd']; deepEqual(_.invoke(array, 'toUpperCase'), ['A', undefined, undefined, 'D']); @@ -5374,7 +5378,7 @@ } }); - test('should accept a falsey `array` argument', 1, function() { + test('should accept a falsey `collection` argument', 1, function() { var expected = _.map(falsey, _.constant([])); var actual = _.map(falsey, function(value, index) { @@ -5386,6 +5390,10 @@ deepEqual(actual, expected); }); + test('should treat number values for `collection` as empty', 1, function() { + deepEqual(_.map(1), []); + }); + test('should be aliased', 1, function() { strictEqual(_.collect, _.map); }); @@ -7410,6 +7418,10 @@ deepEqual(actual.sort(), array); }); + test('should treat number values for `collection` as empty', 1, function() { + deepEqual(_.shuffle(1), []); + }); + _.forEach({ 'literal': 'abc', 'object': Object('abc') @@ -7670,6 +7682,10 @@ deepEqual(actual, [3, 1, 2]); }); + test('should treat number values for `collection` as empty', 1, function() { + deepEqual(_.sortBy(1), []); + }); + test('should support sorting by an array of properties', 1, function() { var actual = _.sortBy(objects, ['a', 'b']); deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);