mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Allow null or undefined elements in _.pluck, _.property, and _.invoke.
This commit is contained in:
14
test/test.js
14
test/test.js
@@ -3636,8 +3636,8 @@
|
||||
|
||||
(function() {
|
||||
test('should invoke a methods on each element of a collection', 1, function() {
|
||||
var actual = _.invoke(['a', 'b', 'c'], 'toUpperCase');
|
||||
deepEqual(actual, ['A', 'B', 'C']);
|
||||
var array = ['a', 'b', 'c'];
|
||||
deepEqual( _.invoke(array, 'toUpperCase'), ['A', 'B', 'C']);
|
||||
});
|
||||
|
||||
test('should work with a function `methodName` argument', 1, function() {
|
||||
@@ -3652,6 +3652,11 @@
|
||||
var object = { 'a': 1, 'b': 2, 'c': 3 };
|
||||
deepEqual(_.invoke(object, 'toFixed', 1), ['1.0', '2.0', '3.0']);
|
||||
});
|
||||
|
||||
test('should work with `null` or `undefined` elements', 1, function() {
|
||||
var array = ['a', null, undefined, 'd'];
|
||||
deepEqual(_.invoke(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -6480,6 +6485,11 @@
|
||||
var object = { 'a': [1], 'b': [1, 2], 'c': [1, 2, 3] };
|
||||
deepEqual(_.pluck(object, 'length'), [1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should work with `null` or `undefined` elements', 1, function() {
|
||||
var objects = [{ 'a': 1 }, null, undefined, { 'a': 4 }];
|
||||
deepEqual(_.pluck(objects, 'a'), [1, undefined, undefined, 4]);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user