mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Add initial test files from lodash v4. (#4172)
* 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.
This commit is contained in:
committed by
John-David Dalton
parent
7606ea3e25
commit
d5ef31929a
50
test/chunk.js
Normal file
50
test/chunk.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { falsey, stubArray } from './utils.js';
|
||||
import chunk from '../chunk.js';
|
||||
|
||||
describe('chunk', function() {
|
||||
var array = [0, 1, 2, 3, 4, 5];
|
||||
|
||||
it('should return chunked arrays', function() {
|
||||
var actual = chunk(array, 3);
|
||||
assert.deepStrictEqual(actual, [[0, 1, 2], [3, 4, 5]]);
|
||||
});
|
||||
|
||||
it('should return the last chunk as remaining elements', function() {
|
||||
var actual = chunk(array, 4);
|
||||
assert.deepStrictEqual(actual, [[0, 1, 2, 3], [4, 5]]);
|
||||
});
|
||||
|
||||
it('should treat falsey `size` values, except `undefined`, as `0`', function() {
|
||||
var expected = lodashStable.map(falsey, function(value) {
|
||||
return value === undefined ? [[0], [1], [2], [3], [4], [5]] : [];
|
||||
});
|
||||
|
||||
var actual = lodashStable.map(falsey, function(size, index) {
|
||||
return index ? chunk(array, size) : chunk(array);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should ensure the minimum `size` is `0`', function() {
|
||||
var values = lodashStable.reject(falsey, lodashStable.isUndefined).concat(-1, -Infinity),
|
||||
expected = lodashStable.map(values, stubArray);
|
||||
|
||||
var actual = lodashStable.map(values, function(n) {
|
||||
return chunk(array, n);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should coerce `size` to an integer', function() {
|
||||
assert.deepStrictEqual(chunk(array, array.length / 4), [[0], [1], [2], [3], [4], [5]]);
|
||||
});
|
||||
|
||||
it('should work as an iteratee for methods like `_.map`', function() {
|
||||
var actual = lodashStable.map([[1, 2], [3, 4]], chunk);
|
||||
assert.deepStrictEqual(actual, [[[1], [2]], [[3], [4]]]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user