mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-15 13:17:50 +00:00
Cleanup "find" tests.
This commit is contained in:
105
test/test.js
105
test/test.js
@@ -5747,12 +5747,12 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
lodashStable.each(['find', 'findLast', 'findIndex', 'findLastIndex', 'findKey', 'findLastKey'], function(methodName) {
|
||||
lodashStable.each(['find', 'findIndex', 'findKey', 'findLast', 'findLastIndex', 'findLastKey'], function(methodName) {
|
||||
QUnit.module('lodash.' + methodName);
|
||||
|
||||
var func = _[methodName];
|
||||
var array = [1, 2, 3, 4],
|
||||
func = _[methodName];
|
||||
|
||||
(function() {
|
||||
var objects = [
|
||||
{ 'a': 0, 'b': 0 },
|
||||
{ 'a': 1, 'b': 1 },
|
||||
@@ -5761,10 +5761,10 @@
|
||||
|
||||
var expected = ({
|
||||
'find': [objects[1], undefined, objects[2]],
|
||||
'findLast': [objects[2], undefined, objects[2]],
|
||||
'findIndex': [1, -1, 2],
|
||||
'findLastIndex': [2, -1, 2],
|
||||
'findKey': ['1', undefined, '2'],
|
||||
'findLast': [objects[2], undefined, objects[2]],
|
||||
'findLastIndex': [2, -1, 2],
|
||||
'findLastKey': ['2', undefined, '2']
|
||||
})[methodName];
|
||||
|
||||
@@ -5812,46 +5812,16 @@
|
||||
|
||||
assert.deepEqual(actual, expecting);
|
||||
});
|
||||
}());
|
||||
|
||||
(function() {
|
||||
var array = [1, 2, 3, 4];
|
||||
|
||||
var expected = ({
|
||||
'find': [0, 1, 2, 3],
|
||||
'findLast': [3, 2, 1, 0],
|
||||
'findIndex': [0, 1, 2, 3],
|
||||
'findLastIndex': [3, 2, 1, 0]
|
||||
})[methodName];
|
||||
|
||||
if (expected != null) {
|
||||
QUnit.test('`_.' + methodName + '` should pass the index as the second argument for `iteratee`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var actual = [];
|
||||
|
||||
func(array, function(n, index) {
|
||||
actual.push(index);
|
||||
return false;
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
}
|
||||
}());
|
||||
|
||||
(function() {
|
||||
var array = [1, 2, 3, 4];
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var expected = ({
|
||||
'find': 1,
|
||||
'findLast': 4,
|
||||
'findIndex': 0,
|
||||
'findLastIndex': 3,
|
||||
'findKey': '0',
|
||||
'findLast': 4,
|
||||
'findLastIndex': 3,
|
||||
'findLastKey': '3'
|
||||
})[methodName];
|
||||
|
||||
@@ -5904,17 +5874,28 @@
|
||||
skipAssert(assert, 2);
|
||||
}
|
||||
});
|
||||
}());
|
||||
});
|
||||
|
||||
(function() {
|
||||
var expected = ({
|
||||
'find': 1,
|
||||
'findLast': 2,
|
||||
'findKey': 'a',
|
||||
'findLastKey': 'b'
|
||||
})[methodName];
|
||||
_.each(['find', 'findIndex', 'findLast', 'findLastIndex'], function(methodName) {
|
||||
var func = _[methodName];
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments for arrays', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var args,
|
||||
array = ['a'];
|
||||
|
||||
func(array, function() {
|
||||
args || (args = slice.call(arguments));
|
||||
});
|
||||
|
||||
assert.deepEqual(args, ['a', 0, array]);
|
||||
});
|
||||
});
|
||||
|
||||
_.each(['find', 'findKey', 'findLast', 'findLastKey'], function(methodName) {
|
||||
var func = _[methodName];
|
||||
|
||||
if (expected != null) {
|
||||
QUnit.test('`_.' + methodName + '` should work with an object for `collection`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
@@ -5922,34 +5903,28 @@
|
||||
return n < 3;
|
||||
});
|
||||
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
}
|
||||
}());
|
||||
|
||||
(function() {
|
||||
var expected = ({
|
||||
'find': ['a', 'b', 'c'],
|
||||
'findLast': ['c', 'b', 'a'],
|
||||
'findKey': ['a', 'b', 'c'],
|
||||
'findLastKey': ['c', 'b', 'a']
|
||||
'find': 1,
|
||||
'findKey': 'a',
|
||||
'findLast': 2,
|
||||
'findLastKey': 'b'
|
||||
})[methodName];
|
||||
|
||||
if (expected != null) {
|
||||
QUnit.test('`_.' + methodName + '` should pass the key as the second argument for `iteratee`', function(assert) {
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should provide correct `predicate` arguments for objects', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var actual = [];
|
||||
var args,
|
||||
object = { 'a': 1 };
|
||||
|
||||
func({ 'a': 1, 'b': 2, 'c': 3 }, function(n, key) {
|
||||
actual.push(key);
|
||||
return false;
|
||||
func(object, function() {
|
||||
args || (args = slice.call(arguments));
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
assert.deepEqual(args, [1, 'a', object]);
|
||||
});
|
||||
}
|
||||
}());
|
||||
});
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user