| name | write-tests |
| description | Write tests following project conventions. Use when adding new tests or modifying existing ones. Use when this capability is needed. |
| metadata | {"author":"getsentry"} |
Write Tests Skill
Write tests using Vitest. Tests are colocated next to source files.
Structure
src/lib/utils.ts
src/lib/utils.test.ts # colocated
src/app/api/stats/route.ts
src/app/api/stats/route.test.ts
src/test-utils/
├── setup.ts # global setup (PGlite, MSW, auth mock)
├── msw-handlers.ts # external API mocks
└── auth.ts # auth test helpers
Auth Testing
Auth is globally mocked. Use helpers to control auth state:
import { mockAuthenticated, mockUnauthenticated } from '@/test-utils/auth';
it('returns 401 when unauthenticated', async () => {
await mockUnauthenticated();
const response = await GET(new Request('http://localhost/api/foo'));
expect(response.status).toBe();
});
(, () => {
();
({ : });
response = ( ());
(response.).();
});