From ad0bcc7de952d68e1cddc96de4e3af513e3a1be7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 22 Dec 2013 01:25:24 -0600 Subject: [PATCH] Add another `_.constant` test for falsey values. --- test/test.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/test.js b/test/test.js index c8742a9c6..c88ff0da9 100644 --- a/test/test.js +++ b/test/test.js @@ -1126,12 +1126,30 @@ (function() { test('should create a function that always returns `value`', 1, function() { var object = { 'a': 1 }, - values = falsey.concat(1, 'a'), + values = falsey.concat(null, null, 1, 'a'), constant = _.constant(object), - expected = _.map(values, function() { return object; }); + expected = _.map(values, function() { return true; }); var actual = _.map(values, function(value, index) { - return index ? constant(value) : constant(); + if (index == 0) { + var result = constant(); + } else if (index == 1) { + result = constant.call({}); + } else { + result = constant(value); + } + return result === object; + }); + + deepEqual(actual, expected); + }); + + test('should work with falsey values', 1, function() { + var expected = _.map(falsey, function() { return true; }); + + var actual = _.map(falsey, function(value, index) { + var constant = index ? _.constant(value) : _.constant(); + return constant() === value || _.isNaN(value); }); deepEqual(actual, expected);