mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Ensure methods accepting a thisArg argument allow null values.
Former-commit-id: 368b943687291f0d7ed02304284ac076ef86e02b
This commit is contained in:
56
test/test.js
56
test/test.js
@@ -1713,7 +1713,61 @@
|
||||
}
|
||||
});
|
||||
|
||||
ok(pass, methodName + ' allows falsey arguments');
|
||||
ok(pass, '_.' + methodName + ' allows falsey arguments');
|
||||
});
|
||||
});
|
||||
|
||||
test('should handle `null` `thisArg` arguments', function() {
|
||||
var thisArg,
|
||||
array = ['a'],
|
||||
callback = function() { thisArg = this; },
|
||||
useStrict = Function('"use strict";return this')() === undefined;
|
||||
|
||||
var funcs = [
|
||||
'countBy',
|
||||
'every',
|
||||
'filter',
|
||||
'find',
|
||||
'forEach',
|
||||
'forIn',
|
||||
'forOwn',
|
||||
'groupBy',
|
||||
'map',
|
||||
'max',
|
||||
'min',
|
||||
'omit',
|
||||
'pick',
|
||||
'reduce',
|
||||
'reduceRight',
|
||||
'reject',
|
||||
'some',
|
||||
'sortBy',
|
||||
'sortedIndex',
|
||||
'times',
|
||||
'uniq'
|
||||
];
|
||||
|
||||
_.each(funcs, function(methodName) {
|
||||
var func = _[methodName],
|
||||
message = '_.' + methodName + ' handles `null` `thisArg` arguments';
|
||||
|
||||
thisArg = undefined;
|
||||
|
||||
if (/^reduce/.test(methodName)) {
|
||||
func(array, callback, 0, null);
|
||||
} else if (methodName == 'sortedIndex') {
|
||||
func(array, 'a', callback, null);
|
||||
} else if (methodName == 'times') {
|
||||
func(1, callback, null);
|
||||
} else {
|
||||
func(array, callback, null);
|
||||
}
|
||||
|
||||
if (useStrict) {
|
||||
deepEqual(thisArg, null, message);
|
||||
} else {
|
||||
equal(thisArg, window, message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user