Skip to content

Commit

Permalink
Add more tests for null thisArg arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Apr 15, 2014
1 parent 734cd0a commit 76c3d25
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10303,14 +10303,18 @@
});
});

test('should handle `null` `thisArg` arguments', 30, function() {
var thisArg,
callback = function() { thisArg = this; },
expected = (function() { return this; }).call(null);
test('should handle `null` `thisArg` arguments', 44, function() {
var expected = (function() { return this; }).call(null);

var funcs = [
'assign',
'clone',
'cloneDeep',
'countBy',
'dropWhile',
'dropRightWhile',
'every',
'flatten',
'filter',
'find',
'findIndex',
Expand All @@ -10325,10 +10329,14 @@
'forOwn',
'forOwnRight',
'groupBy',
'isEqual',
'map',
'mapValues',
'max',
'merge',
'min',
'omit',
'partition',
'pick',
'reduce',
'reduceRight',
Expand All @@ -10337,32 +10345,35 @@
'some',
'sortBy',
'sortedIndex',
'takeWhile',
'takeRightWhile',
'tap',
'times',
'transform',
'uniq'
];

_.each(funcs, function(methodName) {
var array = ['a'],
var actual,
array = ['a'],
func = _[methodName],
message = '`_.' + methodName + '` handles `null` `thisArg` arguments';

thisArg = undefined;

if (/^reduce/.test(methodName)) {
function callback() {
actual = this;
}
if (/^reduce/.test(methodName) || methodName == 'transform') {
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);
} else if (methodName == 'times') {
func(1, callback, null);
} else {
func(array, callback, null);
}

if (expected === null) {
strictEqual(thisArg, null, message);
} else {
strictEqual(thisArg, expected, message);
}
strictEqual(actual, expected, message);
});
});

Expand Down

0 comments on commit 76c3d25

Please sign in to comment.