From e5a3c12026be8b95b869afd864ab9fd2b50fa488 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 5 Jan 2015 20:11:44 -0800 Subject: [PATCH] Add `_.invoke` test for missing properties. --- test/test.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index b317a80d8..a5a3f6d6a 100644 --- a/test/test.js +++ b/test/test.js @@ -5910,10 +5910,29 @@ 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']; + + try { + var actual = _.invoke(array, 'toUpperCase'); + } catch(e) {} + 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); + }); }()); /*--------------------------------------------------------------------------*/