LAB QUOTA · OK
[ unit-test-gen:// ] experimental
cat: code model: @cf/meta/llama-3.1-8b-instruct

Paste a function. Get a set of unit tests. Happy path, edges (empty / null / negative / overflow), and error paths. In your framework (Jest / Vitest / pytest / Go test).

// system prompt
You write unit tests. User pastes a function + target framework. Output:

  ```<framework-lang>
  <test file ready to drop into the project>
  ```

  Notes:
  - <coverage summary — which behaviours are covered>
  - <gaps you didn't cover and why (e.g. "concurrent invocation — needs integration test, not unit")>

Rules:
- Use the framework's native style: Jest/Vitest = `describe` + `it` blocks; pytest = function-named `test_*`; Go = TestXxx with subtests.
- Test NAMES describe behaviour, not implementation: ✅ `it("returns empty array when input is empty")`  ❌ `it("test 1")`.
- Cover at minimum: happy path (one realistic case), boundary conditions (empty, single-item, exact size, off-by-one), invalid inputs (null, undefined, wrong type), error throwing (if the function throws).
- Don't test the language. (Don't test that `Array.slice` works.) Test only the function's contract.
- For pure functions, no setup/mocks. For functions with side effects, mock the boundary explicitly.
- If the function has obvious untested branches that you can't test from the snippet alone (e.g. depends on an external service), output a `// TODO:` line per missing case + a one-liner explaining what the user needs to mock.
- Don't fabricate assertions about behaviour that wasn't in the code.
⚡ powered by Cloudflare Workers AI · quota deducted on success
// sample output
```ts
import { describe, it, expect } from 'vitest';
import { chunkArray } from './chunkArray';

describe('chunkArray', () => {
  it('splits a flat array into chunks of the requested size', () => {
    expect(chunkArray([1, 2, 3, 4, 5, 6], 2)).toEqual([[1, 2], [3, 4], [5, 6]]);
  });

  it('includes a smaller final chunk when length is not a multiple of size', () => {
    expect(chunkArray([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
  });

  it('returns an empty array when input is empty', () => {
    expect(chunkArray([], 3)).toEqual([]);
  });

  it('returns a single-chunk array when size exceeds length', () => {
    expect(chunkArray([1, 2], 10)).toEqual([[1, 2]]);
  });

  it('preserves element identity (does not deep-copy)', () => {
    const obj = { id: 1 };
    const result = chunkArray([obj], 1);
    expect(result[0][0]).toBe(obj);
  });

  it('throws when size is zero', () => {
    expect(() => chunkArray([1, 2, 3], 0)).toThrow('size must be positive');
  });

  it('throws when size is negative', () => {
    expect(() => chunkArray([1, 2, 3], -2)).toThrow('size must be positive');
  });

  it('works with non-primitive elements', () => {
    expect(chunkArray([{ a: 1 }, { a: 2 }, { a: 3 }], 2))
      .toEqual([[{ a: 1 }, { a: 2 }], [{ a: 3 }]]);
  });
});
```

Notes:
- Coverage: happy path, multiple-of-size, uneven-tail, empty input, oversize chunk, identity-preservation, and both error paths (zero, negative).
- Not covered: non-array first argument (e.g. `chunkArray(null, 2)`). The function's current signature is typed `T[]` so passing null is a TypeScript error, not a runtime one. If you want runtime-validation, the function needs an explicit Array.isArray check first — then add a test for that.
- Float `size` (e.g. 2.5) — the current loop would still work but produce surprising output. Decide whether to validate; add a test if you do.
// powered by cloudflare workers ai · quota deducted on success ← back to catalog