Vitest Testing Skill
This skill enforces standards for writing reliable unit and integration tests using Vitest.
Core Directives
- •Test Location: Place tests alongside the code they test (e.g.,
utils.test.tsnext toutils.ts) or in a dedicated__tests__directory. - •Mocking: Use
vi.mock()sparingly. Prefer testing pure functions. When mocking is necessary (e.g., for database calls, Clerk auth), mock the module boundaries clearly. - •Test Structure: Use
describeblocks to group related tests andit/testfor individual assertions. Follow the Arrange-Act-Assert pattern within tests. - •Edge Cases: Write tests not just for the happy path, but specifically for edge cases, null states, missing permissions, and invalid inputs.
- •Configuration: Ensure
vitest.config.tsis configured to handle TypeScript paths (tsconfigPaths()) and any required setup files. - •Execution: Tests must be fast and reproducible. Do not rely on shared global state between tests.