Add more tests for null thisArg arguments.

This commit is contained in:
John-David Dalton
2014-04-14 21:35:10 -07:00
parent ff25b4cb46
commit cd62b2a209

View File

@@ -10303,14 +10303,18 @@
}); });
}); });
test('should handle `null` `thisArg` arguments', 30, function() { test('should handle `null` `thisArg` arguments', 44, function() {
var thisArg, var expected = (function() { return this; }).call(null);
callback = function() { thisArg = this; },
expected = (function() { return this; }).call(null);
var funcs = [ var funcs = [
'assign',
'clone',
'cloneDeep',
'countBy', 'countBy',
'dropWhile',
'dropRightWhile',
'every', 'every',
'flatten',
'filter', 'filter',
'find', 'find',
'findIndex', 'findIndex',
@@ -10325,10 +10329,14 @@
'forOwn', 'forOwn',
'forOwnRight', 'forOwnRight',
'groupBy', 'groupBy',
'isEqual',
'map', 'map',
'mapValues',
'max', 'max',
'merge',
'min', 'min',
'omit', 'omit',
'partition',
'pick', 'pick',
'reduce', 'reduce',
'reduceRight', 'reduceRight',
@@ -10337,32 +10345,35 @@
'some', 'some',
'sortBy', 'sortBy',
'sortedIndex', 'sortedIndex',
'takeWhile',
'takeRightWhile',
'tap',
'times', 'times',
'transform',
'uniq' 'uniq'
]; ];
_.each(funcs, function(methodName) { _.each(funcs, function(methodName) {
var array = ['a'], var actual,
array = ['a'],
func = _[methodName], func = _[methodName],
message = '`_.' + methodName + '` handles `null` `thisArg` arguments'; message = '`_.' + methodName + '` handles `null` `thisArg` arguments';
thisArg = undefined; function callback() {
actual = this;
if (/^reduce/.test(methodName)) { }
if (/^reduce/.test(methodName) || methodName == 'transform') {
func(array, callback, 0, null); func(array, callback, 0, null);
} else if (methodName == 'sortedIndex') { } else if (_.contains(['assign', 'merge'], methodName)) {
func(array, array, callback, null);
} else if (_.contains(['isEqual', 'sortedIndex'], methodName)) {
func(array, 'a', callback, null); func(array, 'a', callback, null);
} else if (methodName == 'times') { } else if (methodName == 'times') {
func(1, callback, null); func(1, callback, null);
} else { } else {
func(array, callback, null); func(array, callback, null);
} }
strictEqual(actual, expected, message);
if (expected === null) {
strictEqual(thisArg, null, message);
} else {
strictEqual(thisArg, expected, message);
}
}); });
}); });