Ensure the fp iteratee wrapper enforces arity for functions with a length of 0.

This commit is contained in:
John-David Dalton
2015-12-14 08:06:29 -08:00
parent 41985d8c1a
commit 0706af1543
2 changed files with 23 additions and 1 deletions

View File

@@ -102,7 +102,7 @@ function baseConvert(util, name, func) {
arity = arity > 2 ? (arity - 2) : 1;
func = iteratee(func);
var length = func.length;
return length <= arity ? func : baseAry(func, arity);
return (length && length <= arity) ? func : baseAry(func, arity);
};
},
'mixin': function(mixin) {

View File

@@ -567,6 +567,28 @@
/*--------------------------------------------------------------------------*/
QUnit.module('reduce methods');
_.each(['reduce', 'reduceRight'], function(methodName) {
var func = fp[methodName],
array = [1, 2, 3],
isReduce = methodName == 'reduce';
QUnit.test('`_.' + methodName + '` should provide the correct `iteratee` arguments', function(assert) {
assert.expect(1);
var args;
func(function() {
args || (args = slice.call(arguments));
})(0, array);
assert.deepEqual(args, isReduce ? [0, 1] : [0, 3]);
});
});
/*--------------------------------------------------------------------------*/
QUnit.module('fp.runInContext');
(function() {