Files
web/packages/common/utils/chunk.test.ts
2025-06-30 14:17:49 +02:00

26 lines
649 B
TypeScript

import { describe, expect, it } from "vitest"
import { chunk } from "./chunk"
describe("chunk", () => {
it("should split an array into equally sized chunks of specified size", () => {
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const size = 3
const expected = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]
expect(chunk(array, size)).toEqual(expected)
})
it("should split an array into equally sized chunks of specified size", () => {
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const size = 4
const expected = [[1, 2, 3, 4], [5, 6, 7, 8], [9]]
expect(chunk(array, size)).toEqual(expected)
})
})