1 import chunk from './chunk';
3 describe('chunk()', () => {
4 it('creates an array of chunks of a given other array of fixed size', () => {
5 const output = chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'], 3);
13 expect(output).toEqual(expected);
16 it('defaults to a chunk size of 1 ', () => {
17 const output = chunk(['a', 'b', 'c']);
19 const expected = [['a'], ['b'], ['c']];
21 expect(output).toEqual(expected);
24 it('creates the last chunk equal to the size of remaining elements if not exactly divisible by the chunk size', () => {
25 const output = chunk(['a', 'b', 'c', 'd', 'e'], 2);
27 const expected = [['a', 'b'], ['c', 'd'], ['e']];
29 expect(output).toEqual(expected);
32 it("doesn't mutate the input array", () => {
33 const input = ['a', 'b', 'c'];
37 expect(input).toEqual(['a', 'b', 'c']);
40 it('returns an empty array given no input', () => {
41 const output = chunk();
43 expect(output).toEqual([]);