Prompt file imported from dskhys0222/dskhys (
.github/prompts/write-tests.prompt.md). Copyright stays with the author.
Write comprehensive Vitest tests for the provided code.
-
Identify the type of code being tested:
- Express route → use Supertest patterns
- React component → use Testing Library patterns
- Pure function / utility / repository → use Vitest with
describe/it/expect
-
Cover:
- Happy path (expected behavior)
- Edge cases (empty input, boundary values)
- Error/failure paths (invalid input, rejected promises)
- Auth failure (401) for protected routes
-
Follow conventions in testing.instructions.md:
- Name tests:
it('should <behavior> when <condition>') - Use
vi.fn()/vi.mock()for dependencies - Reset mocks in
beforeEach(() => vi.clearAllMocks()) - Query by accessible role in UI tests
- Name tests:
Place the test file adjacent to the source file as <filename>.test.ts or <filename>.test.tsx.