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