From 0a1036c78f6622cc6839dae41b32a93fa89decd9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 7 Oct 2012 18:18:20 -0700 Subject: [PATCH] Add unit tests to check "Collections" methods return values. Former-commit-id: 6ac6cd97414035f74a102a51e913099e744d9a93 --- test/test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index 02a838f14..2d11a12a1 100644 --- a/test/test.js +++ b/test/test.js @@ -1727,6 +1727,17 @@ (function() { test('should allow falsey arguments', function() { + var returnArrays = [ + 'filter', + 'invoke', + 'map', + 'pluck', + 'reject', + 'sortBy', + 'toArray', + 'where' + ]; + var funcs = _.without.apply(_, [_.functions(_)].concat([ '_', '_iteratorTemplate', @@ -1748,17 +1759,24 @@ ])); _.each(funcs, function(methodName) { - var func = _[methodName], + var actual = [], + expected = _.times(falsey.length, function() { return []; }), + func = _[methodName], pass = true; _.each(falsey, function(value, index) { try { - index ? func(value) : func(); + actual.push(index ? func(value) : func()); } catch(e) { pass = false; } }); + if (_.indexOf(returnArrays, methodName) > -1) { + deepEqual(actual, expected, '_.' + methodName + ' returns an array'); + } else { + skipTest(falsey.length); + } ok(pass, '_.' + methodName + ' allows falsey arguments'); }); });