Use this skill when writing new features, fixing bugs, or refactoring TypeScript code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.
As a [role], I want to [action], so that [benefit]
Write a test that describes the expected behavior. It must fail for the right reason — missing implementation, not a broken test setup.
import { describe, it, expect } from 'vitest'
import { createUser } from './userService'
describe('createUser', () => {
it('returns the created user with hashed password', async () => {
const result = await createUser({ email: '[email protected]', password: 'secret' })
expect(result.email).toBe('[email protected]')
expect(result.password).not.toBe('secret') // should be hashed
})
it('throws when email already exists', async () => {
await createUser({ email: '[email protected]', password: 'secret' })
await expect(createUser({ email: '[email protected]', password: 'other' }))
.rejects.toThrow('Email already in use')
})
})
Run and verify failure:
pnpm test -- --reporter=verbose createUser
RED gate: the test must compile, execute, and fail for the intended reason. A test that was only written but not run does not count as RED.
Git checkpoint: