Vitest Unit Tests From Function

coding · Claude Code · free

Write Vitest unit tests for this function. Test behavior, not implementation. Cover, in this order: 1. The one contract sentence the function promises — one test that proves it 2. Happy path (2 3 realistic inputs, not 1 + 1) 3. Boundaries (empty, single element, max, min, unicode, whitespace only) 4. Error paths (thrown, rejected, or returned) — assert the shape, not the message 5. Determinism / idempotency where relevant 6. External deps mocked at the module boundary with vi.mock, not spied inline Rules: describe names the unit, it names the behavior in plain English, one behavior per test, no shared mutable state. Add one it.fails() documenting a known bug if you spot one.

#testing #vitest #unit-tests