mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { _, identity, stubZero, falsey } from './utils.js';
|
|
|
|
describe('findIndex and indexOf', function() {
|
|
lodashStable.each(['findIndex', 'indexOf'], function(methodName) {
|
|
var array = [1, 2, 3, 1, 2, 3],
|
|
func = _[methodName],
|
|
resolve = methodName == 'findIndex' ? lodashStable.curry(lodashStable.eq) : identity;
|
|
|
|
it('`_.' + methodName + '` should return the index of the first matched value', function() {
|
|
assert.strictEqual(func(array, resolve(3)), 2);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should work with a positive `fromIndex`', function() {
|
|
assert.strictEqual(func(array, resolve(1), 2), 3);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should work with a `fromIndex` >= `length`', function() {
|
|
var values = [6, 8, Math.pow(2, 32), Infinity],
|
|
expected = lodashStable.map(values, lodashStable.constant([-1, -1, -1]));
|
|
|
|
var actual = lodashStable.map(values, function(fromIndex) {
|
|
return [
|
|
func(array, resolve(undefined), fromIndex),
|
|
func(array, resolve(1), fromIndex),
|
|
func(array, resolve(''), fromIndex)
|
|
];
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should work with a negative `fromIndex`', function() {
|
|
assert.strictEqual(func(array, resolve(2), -3), 4);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should work with a negative `fromIndex` <= `-length`', function() {
|
|
var values = [-6, -8, -Infinity],
|
|
expected = lodashStable.map(values, stubZero);
|
|
|
|
var actual = lodashStable.map(values, function(fromIndex) {
|
|
return func(array, resolve(1), fromIndex);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should treat falsey `fromIndex` values as `0`', function() {
|
|
var expected = lodashStable.map(falsey, stubZero);
|
|
|
|
var actual = lodashStable.map(falsey, function(fromIndex) {
|
|
return func(array, resolve(1), fromIndex);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('`_.' + methodName + '` should coerce `fromIndex` to an integer', function() {
|
|
assert.strictEqual(func(array, resolve(2), 1.2), 1);
|
|
});
|
|
});
|
|
});
|