mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Add result of array tests.
This commit is contained in:
45
test/test.js
45
test/test.js
@@ -8620,18 +8620,23 @@
|
|||||||
'compact',
|
'compact',
|
||||||
'difference',
|
'difference',
|
||||||
'filter',
|
'filter',
|
||||||
|
'first',
|
||||||
'flatten',
|
'flatten',
|
||||||
'functions',
|
'functions',
|
||||||
'initial',
|
'initial',
|
||||||
'intersection',
|
'intersection',
|
||||||
'invoke',
|
'invoke',
|
||||||
|
'last',
|
||||||
'keys',
|
'keys',
|
||||||
'map',
|
'map',
|
||||||
'pairs',
|
'pairs',
|
||||||
'pluck',
|
'pluck',
|
||||||
|
'pull',
|
||||||
'range',
|
'range',
|
||||||
'reject',
|
'reject',
|
||||||
|
'remove',
|
||||||
'rest',
|
'rest',
|
||||||
|
'sample',
|
||||||
'shuffle',
|
'shuffle',
|
||||||
'sortBy',
|
'sortBy',
|
||||||
'times',
|
'times',
|
||||||
@@ -8664,13 +8669,13 @@
|
|||||||
|
|
||||||
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
||||||
|
|
||||||
test('should accept falsey arguments', 155, function() {
|
test('should accept falsey arguments', 157, function() {
|
||||||
var isExported = '_' in root,
|
var emptyArrays = _.map(falsey, function() { return []; }),
|
||||||
|
isExported = '_' in root,
|
||||||
oldDash = root._;
|
oldDash = root._;
|
||||||
|
|
||||||
|
|
||||||
_.forEach(acceptFalsey, function(methodName) {
|
_.forEach(acceptFalsey, function(methodName) {
|
||||||
var expected = _.map(falsey, function() { return []; }),
|
var expected = emptyArrays,
|
||||||
func = _[methodName],
|
func = _[methodName],
|
||||||
pass = true;
|
pass = true;
|
||||||
|
|
||||||
@@ -8689,7 +8694,11 @@
|
|||||||
delete root._;
|
delete root._;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_.indexOf(returnArrays, methodName) > -1) {
|
else if (methodName == 'pull') {
|
||||||
|
expected = falsey;
|
||||||
|
}
|
||||||
|
if (_.contains(returnArrays, methodName) &&
|
||||||
|
!_.contains(['first', 'last', 'sample'], methodName)) {
|
||||||
deepEqual(actual, expected, '_.' + methodName + ' returns an array');
|
deepEqual(actual, expected, '_.' + methodName + ' returns an array');
|
||||||
}
|
}
|
||||||
ok(pass, '`_.' + methodName + '` accepts falsey arguments');
|
ok(pass, '`_.' + methodName + '` accepts falsey arguments');
|
||||||
@@ -8703,6 +8712,32 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return an array', 64, function() {
|
||||||
|
var array = [1, 2, 3];
|
||||||
|
|
||||||
|
_.forEach(returnArrays, function(methodName) {
|
||||||
|
var actual,
|
||||||
|
func = _[methodName];
|
||||||
|
|
||||||
|
switch (methodName) {
|
||||||
|
case 'invoke':
|
||||||
|
actual = func(array, 'toFixed');
|
||||||
|
break;
|
||||||
|
case 'first':
|
||||||
|
case 'last':
|
||||||
|
case 'sample':
|
||||||
|
actual = func(array, 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
actual = func(array);
|
||||||
|
}
|
||||||
|
ok(_.isArray(actual), '_.' + methodName + ' returns an array');
|
||||||
|
|
||||||
|
var isPull = methodName == 'pull';
|
||||||
|
equal(actual === array, isPull, '_.' + methodName + ' should ' + (isPull ? '' : 'not ') + 'return the provided array');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('should reject falsey arguments', 14, function() {
|
test('should reject falsey arguments', 14, function() {
|
||||||
_.forEach(rejectFalsey, function(methodName) {
|
_.forEach(rejectFalsey, function(methodName) {
|
||||||
var expected = _.map(falsey, function() { return true; }),
|
var expected = _.map(falsey, function() { return true; }),
|
||||||
|
|||||||
Reference in New Issue
Block a user