| name | unit-test |
| description | Applies project unit test conventions with Vitest and @solidjs/testing-library. Use when writing or editing .spec.ts files, including DOM tests, module mocking, assertions, async/error handling, and time-based tests. |
Unit Test
Open and apply the reference files for the relevant section before working.
Core Rules
- If tests already exist, verify current results first with Wallaby MCP, then Vitest if needed; fix existing failures before adding tests.
- Use Vitest, and use
@solidjs/testing-library for Solid.js DOM tests.
- Place tests in the target directory's
__tests__ folder and name files {targetFileName}.spec.ts.
- Start test names with
should, and split multi-function targets with describe blocks.
- Do not modify the code under test by default. If the target is hard to unit test because logic is embedded in CLI, UI, I/O, or lifecycle code, ask whether to first extract the behavior into pure, importable logic functions, then test those functions and keep only smoke coverage for the wrapper.
- For DOM tests, add
/** @vitest-environment jsdom */ at the top of the file.
- Aim for 100% coverage; when impossible, add ignore comments and document the reason.
- Verify tests and coverage after changes, then fix lint issues.
- See ./rules/assertion-patterns.md and ./examples/module-mocking.md for assertion and mocking examples.
- See ./examples/async-assertion.md, ./examples/error-assertion.md, and ./examples/time-based-testing.md for specialized patterns.