Ensure _.compose returns a noop function when no arguments are provided.

This commit is contained in:
John-David Dalton
2014-06-21 23:49:50 -07:00
parent 2f1346fefa
commit a3049b6f94
2 changed files with 14 additions and 0 deletions

View File

@@ -5372,6 +5372,9 @@
funcsLength = funcs.length,
length = funcsLength;
if (!length) {
return function() {};
}
while (length--) {
if (!isFunction(funcs[length])) {
throw new TypeError(funcErrorText);

View File

@@ -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();