Files
lodash/test/chunk.spec.js
tison bd518dd906 test: partially fix broken tests (#5733)
* test: fix throttle.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix pickBy.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix isBuffer.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: partially fix attempt.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: partially fix dropRightWhile.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix defer.spec.js and rest.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix invoke.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix isArray.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: partially fix iteration-methods.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix xor-methods.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix property.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix ary.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix omit-methods.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix debounce-and-throttle.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix unzip-and-zip.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix toPairs-methods.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix exit-early.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: temporarily comment out takeWhile and dropWhile tests

Signed-off-by: tison <wander4096@gmail.com>

* test: partially fix union*.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix startsWith-and-endsWith.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix isNil.spec.js

Signed-off-by: tison <wander4096@gmail.com>

* test: fix some of syntax errors

Signed-off-by: tison <wander4096@gmail.com>

---------

Signed-off-by: tison <wander4096@gmail.com>
2023-09-21 07:40:27 -07:00

49 lines
1.4 KiB
JavaScript

import lodashStable from 'lodash';
import { falsey, stubArray } from './utils';
import chunk from '../src/chunk';
describe('chunk', () => {
const array = [0, 1, 2, 3, 4, 5];
it('should return chunked arrays', () => {
const actual = chunk(array, 3);
expect(actual).toEqual([
[0, 1, 2],
[3, 4, 5],
]);
});
it('should return the last chunk as remaining elements', () => {
const actual = chunk(array, 4);
expect(actual).toEqual([
[0, 1, 2, 3],
[4, 5],
]);
});
it('should treat falsey `size` values, except `undefined`, as `0`', () => {
const expected = lodashStable.map(falsey, (value) =>
value === undefined ? [[0], [1], [2], [3], [4], [5]] : [],
);
const actual = lodashStable.map(falsey, (size, index) =>
index ? chunk(array, size) : chunk(array),
);
expect(actual).toEqual(expected);
});
it('should ensure the minimum `size` is `0`', () => {
const values = lodashStable.reject(falsey, lodashStable.isUndefined).concat(-1, -Infinity);
const expected = lodashStable.map(values, stubArray);
const actual = lodashStable.map(values, (n) => chunk(array, n));
expect(actual).toEqual(expected);
});
it('should coerce `size` to an integer', () => {
expect(chunk(array, array.length / 4)).toEqual([[0], [1], [2], [3], [4], [5]]);
});
});