mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27: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.
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { falsey, stubArray, LARGE_ARRAY_SIZE } from './utils.js';
|
|
import initial from '../initial.js';
|
|
|
|
describe('initial', function() {
|
|
var array = [1, 2, 3];
|
|
|
|
it('should accept a falsey `array`', function() {
|
|
var expected = lodashStable.map(falsey, stubArray);
|
|
|
|
var actual = lodashStable.map(falsey, function(array, index) {
|
|
try {
|
|
return index ? initial(array) : initial();
|
|
} catch (e) {}
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should exclude last element', function() {
|
|
assert.deepStrictEqual(initial(array), [1, 2]);
|
|
});
|
|
|
|
it('should return an empty when querying empty arrays', function() {
|
|
assert.deepStrictEqual(initial([]), []);
|
|
});
|
|
|
|
it('should work as an iteratee for methods like `_.map`', function() {
|
|
var array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
|
|
actual = lodashStable.map(array, initial);
|
|
|
|
assert.deepStrictEqual(actual, [[1, 2], [4, 5], [7, 8]]);
|
|
});
|
|
|
|
it('should work in a lazy sequence', function() {
|
|
var array = lodashStable.range(LARGE_ARRAY_SIZE),
|
|
values = [];
|
|
|
|
var actual = _(array).initial().filter(function(value) {
|
|
values.push(value);
|
|
return false;
|
|
})
|
|
.value();
|
|
|
|
assert.deepEqual(actual, []);
|
|
assert.deepEqual(values, initial(array));
|
|
|
|
values = [];
|
|
|
|
actual = _(array).filter(function(value) {
|
|
values.push(value);
|
|
return isEven(value);
|
|
})
|
|
.initial()
|
|
.value();
|
|
|
|
assert.deepEqual(actual, initial(lodashStable.filter(array, isEven)));
|
|
assert.deepEqual(values, array);
|
|
});
|
|
});
|