From a3049b6f94e3af48d21d350dd156e36905ee6b87 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 21 Jun 2014 23:49:50 -0700 Subject: [PATCH] Ensure `_.compose` returns a noop function when no arguments are provided. --- lodash.js | 3 +++ test/test.js | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lodash.js b/lodash.js index de6facfa0..d19e6b84d 100644 --- a/lodash.js +++ b/lodash.js @@ -5372,6 +5372,9 @@ funcsLength = funcs.length, length = funcsLength; + if (!length) { + return function() {}; + } while (length--) { if (!isFunction(funcs[length])) { throw new TypeError(funcErrorText); diff --git a/test/test.js b/test/test.js index b1f5586b4..021c25e28 100644 --- a/test/test.js +++ b/test/test.js @@ -1503,6 +1503,17 @@ notStrictEqual(_.compose(_.noop), _.noop); }); + test('should return a noop function when no arguments are provided', 2, function() { + var composed = _.compose(); + + try { + strictEqual(composed(), undefined); + } catch(e) { + ok(false); + } + notStrictEqual(composed, _.noop); + }); + test('should return a wrapped value when chaining', 1, function() { if (!isNpm) { var actual = _(_.noop).compose();