mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Add _.invoke test for missing properties.
This commit is contained in:
21
test/test.js
21
test/test.js
@@ -5910,10 +5910,29 @@
|
|||||||
deepEqual(_.invoke(1), []);
|
deepEqual(_.invoke(1), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with nullish elements', 1, function() {
|
test('should not error on nullish elements', 1, function() {
|
||||||
var array = ['a', null, undefined, 'd'];
|
var array = ['a', null, undefined, 'd'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
var actual = _.invoke(array, 'toUpperCase');
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
deepEqual(_.invoke(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
|
deepEqual(_.invoke(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not error on elements with missing properties', 1, function() {
|
||||||
|
var objects = _.map(falsey.concat(_.constant(1)), function(value) {
|
||||||
|
return { 'a': value };
|
||||||
|
});
|
||||||
|
|
||||||
|
var expected = _.times(objects.length - 1, _.constant(undefined)).concat(1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
var actual = _.invoke(objects, 'a');
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
|
deepEqual(actual, expected);
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user