Use when writing, fixing, refactoring, or reviewing tests in this repo or similar TypeScript apps. Covers Vitest, React Testing Library, TypeScript test typecheck, typed fixtures, mocking strategy, warning cleanup, and validation workflow for web and API tests.
Use this skill when adding or fixing tests. The goal is not just "make tests pass" — it is:
check, check:test, test, and lint greenThese recommendations align with current official guidance:
await act(async () => ...) for updates that cross async boundaries.user-event over low-level fireEvent for realistic interactions when possible.any.apps/webbun run check:testbun run checkbun run testbun run lintapps/apibun run check:testbun run checkbun testbun run lintIf one of these is missing, add the minimal config/scripts needed rather than skipping the gate.
screen.getByRole, getByLabelText, and other semantic queries.user-event for realistic interactions when practical.fireEvent only when the interaction is intentionally low-level or user-event is not a good fit.container.querySelector(...) unless there is no meaningful accessible query.act(...)await act(async () => ...).asChild where appropriate or pass plain text when the trigger itself renders a button.tsconfig.test.json when the production config excludes tests.Create shared builders for repeated domain objects:
makeUser()makeSession()makeProject()makeTender() / makeGrant()Fixture builders should:
Partial<T> overridesPrefer this order:
as any only as a last resortBad:
const mocked = vi.mocked as any repeated across many filesBetter:
vi.spyOn for existing objects when you care about original shape.vi.mock at module boundaries.src/test/setup/ or equivalent shared helpers.Warnings that should usually be fixed:
act(...) warnings caused by test interactionsWarnings that may be acceptable if intentional and non-failing:
Do not destabilize green tests just to eliminate every warning. Prefer low-risk cleanup.
@/ imports for app source imports.apps/websrc/__tests__/helpers/.src/__tests__/setup.ts.src/__tests__/types/.apps/apisrc/test/setup/.Stop fixing leaf tests one-by-one if you see repeated failures from:
Create or improve a helper first, then resume the leaf tests.
A test task is done only when:
When asked to write or fix tests: