Test coverage and quality review — what needs tests, test quality assessment, anti-patterns, and the testing pyramid for Next.js + Supabase applications.
// ❌ Testing mocks, not code — this test will pass even if fetchUsers is broken
vi.mock('@/lib/api', () => ({
fetchUsers: vi.fn().mockResolvedValue([{ id: 1, name: 'Test' }])
}))
it('displays users', async () => {
render(<UserList />)
await waitFor(() => expect(screen.getByText('Test')).toBeInTheDocument())
})
// This tells you the component renders mock data, not that your API integration works
// ✅ Integration test with real data layer (test database)
it('displays users from the database', async () => {
await seedTestDatabase([{ id: 1, name: 'Test' }])
render(<UserList />)
await waitFor(() => expect(screen.getByText('Test')).toBeInTheDocument())
})
Date.now() or new Date() in assertions (use vi.useFakeTimers())
setTimeout races (use vi.advanceTimersByTime())
Order-dependent tests (test B depends on state from test A)
Network calls to real APIs (mock them or use MSW)
Anti-Pattern 6: Array Index as Key
// Not a test issue, but flag in component tests:
// ❌ Causes bugs on reorder, delete, insert
{items.map((item, i) => <ListItem key={i} item={item} />)}
// ✅ Stable identity
{items.map(item => <ListItem key={item.id} item={item} />)}
Testing Architecture for Our Stack
The Pyramid
┌──────┐
│ E2E │ Playwright: 5-10 critical user journeys
│ │ Login → Create → View → Edit → Delete
├──────┤
│ Integ│ Vitest + real DB: API routes, Server Actions,
│ation │ data layer, auth flows (20-50 tests)
├──────┤
│ Unit │ Vitest: pure functions, utils, hooks,
│ │ validation schemas, transforms (100+ tests)
└──────┘
Tool Mapping
Layer
Tool
What to Test
Unit
Vitest
Pure functions, Zod schemas, transforms, hooks
Integration
Vitest + Supabase test project
API routes, Server Actions, DB queries, RLS policies
E2E
Playwright
Full user journeys: signup → use feature → logout
Component
Vitest + Testing Library
User interaction, form submission, error states
React Testing Library Philosophy (from the repo)
"The more your tests resemble the way your software is used, the more confidence they can give you."
Query by role, label, text — not by class, ID, or test-id
Fire real events (userEvent.click) not synthetic (fireEvent.click)
Assert on what the user sees, not on component internals
If you can't test something without accessing component internals, your component API needs refactoring
Database/RLS Test Patterns
// Test RLS policies directly
describe('RLS: users table', () => {
it('user can only read own profile', async () => {
const userA = await createTestUser()
const userB = await createTestUser()
const clientA = createClientAs(userA)
const { data } = await clientA.from('profiles').select('*')
expect(data).toHaveLength(1)
expect(data[0].id).toBe(userA.id)
// userB's profile is not visible
})
it('unauthenticated user cannot read profiles', async () => {
const anonClient = createAnonClient()
const { data, error } = await anonClient.from('profiles').select('*')
expect(data).toHaveLength(0) // RLS blocks everything
})
})
Sources
testing-library/react-testing-library documentation and guiding principles
vitest-dev/vitest configuration and best practices
Kent C. Dodds: Testing Implementation Details
Supabase testing documentation
Changelog
2026-03-21: Initial skill — test review for Next.js + Supabase
1---2name: testing-review3description: Test coverage and quality review — what needs tests, test quality assessment, anti-patterns, and the testing pyramid for Next.js + Supabase applications.4metadata:5 source: https://skillmd.com/skills/nickgallick/testing-review6---78# Testing Review910## Quick Reference — PR Test Checklist1112**When reviewing a PR, check:**131. [ ] Every new function with branching logic has a test142. [ ] Every new API route has at least one happy-path + one error-path test153. [ ] Every new Server Action has validation tested164. [ ] Financial/payment logic has comprehensive tests (P0 if missing)175. [ ] Auth flows have test coverage186. [ ] Edge cases covered: empty arrays, null inputs, boundary values197. [ ] Tests are deterministic (no time-dependent, no random, no network)208. [ ] Test descriptions describe behavior, not implementation2122---2324## What to Flag When Tests Are Missing2526### P0 — Block merge without tests:27- Payment/financial logic (transfers, billing, coin transactions)28- Authentication flows (login, signup, token refresh, logout)29- Authorization checks (RLS policies, ownership verification)30- Data migrations that modify existing data3132### P1 — Should have tests:33- Complex business logic with branching (>2 branches)34- API routes with input validation35- Server Actions that mutate data36- Utility functions used in >2 places37- Error handling paths3839### OK without tests (don't flag):40- Pure UI components (just layout/styling, no logic)41- Type-only files (`types.ts`, `interfaces.ts`)42- Configuration files (`next.config.ts`, `tailwind.config.ts`)43- One-line utility functions that are trivially correct44- Generated code (Supabase types, migration files)4546---4748## Test Quality Review4950### Anti-Pattern 1: Testing Implementation, Not Behavior51```ts52// ❌ Tests internal state — breaks if you refactor53it('sets loading to true', () => {54 const { result } = renderHook(() => useUsers())55 expect(result.current.loading).toBe(true)56})5758// ✅ Tests behavior — survives refactors59it('shows loading spinner while fetching users', async () => {60 render(<UserList />)61 expect(screen.getByRole('progressbar')).toBeInTheDocument()62 await waitFor(() => {63 expect(screen.getByText('John Doe')).toBeInTheDocument()64 })65})66```6768### Anti-Pattern 2: Tests with No Assertions69```ts70// ❌ Passes but verifies NOTHING71it('renders without crashing', () => {72 render(<Dashboard />)73})7475// ✅ Actually verifies something76it('renders the dashboard title', () => {77 render(<Dashboard />)78 expect(screen.getByRole('heading', { name: 'Dashboard' })).toBeInTheDocument()79})80```8182### Anti-Pattern 3: Over-Mocking83```ts84// ❌ Testing mocks, not code — this test will pass even if fetchUsers is broken85vi.mock('@/lib/api', () => ({86 fetchUsers: vi.fn().mockResolvedValue([{ id: 1, name: 'Test' }])87}))88it('displays users', async () => {89 render(<UserList />)90 await waitFor(() => expect(screen.getByText('Test')).toBeInTheDocument())91})92// This tells you the component renders mock data, not that your API integration works9394// ✅ Integration test with real data layer (test database)95it('displays users from the database', async () => {96 await seedTestDatabase([{ id: 1, name: 'Test' }])97 render(<UserList />)98 await waitFor(() => expect(screen.getByText('Test')).toBeInTheDocument())99})100```101102### Anti-Pattern 4: Only Happy Path103```ts104// ❌ Only tests success case105it('creates a user', async () => {106 const result = await createUser({ name: 'John', email: 'john@test.com' })107 expect(result.success).toBe(true)108})109110// ✅ Tests error cases too111it('rejects invalid email', async () => {112 const result = await createUser({ name: 'John', email: 'not-an-email' })113 expect(result.success).toBe(false)114 expect(result.error).toContain('email')115})116117it('rejects duplicate email', async () => {118 await createUser({ name: 'John', email: 'john@test.com' })119 const result = await createUser({ name: 'Jane', email: 'john@test.com' })120 expect(result.success).toBe(false)121})122123it('handles database errors gracefully', async () => {124 // Simulate DB failure125 vi.spyOn(supabase, 'from').mockRejectedValueOnce(new Error('connection lost'))126 const result = await createUser({ name: 'John', email: 'john@test.com' })127 expect(result.success).toBe(false)128 expect(result.error).not.toContain('connection lost') // no internal details leaked129})130```131132### Anti-Pattern 5: Flaky Tests133Sources of flakiness:134- `Date.now()` or `new Date()` in assertions (use `vi.useFakeTimers()`)135- `setTimeout` races (use `vi.advanceTimersByTime()`)136- Order-dependent tests (test B depends on state from test A)137- Network calls to real APIs (mock them or use MSW)138139### Anti-Pattern 6: Array Index as Key140```tsx141// Not a test issue, but flag in component tests:142// ❌ Causes bugs on reorder, delete, insert143{items.map((item, i) => <ListItem key={i} item={item} />)}144145// ✅ Stable identity146{items.map(item => <ListItem key={item.id} item={item} />)}147```148149---150151## Testing Architecture for Our Stack152153### The Pyramid154```155 ┌──────┐156 │ E2E │ Playwright: 5-10 critical user journeys157 │ │ Login → Create → View → Edit → Delete158 ├──────┤159 │ Integ│ Vitest + real DB: API routes, Server Actions,160 │ation │ data layer, auth flows (20-50 tests)161 ├──────┤162 │ Unit │ Vitest: pure functions, utils, hooks,163 │ │ validation schemas, transforms (100+ tests)164 └──────┘165```166167### Tool Mapping168| Layer | Tool | What to Test |169|-------|------|-------------|170| Unit | Vitest | Pure functions, Zod schemas, transforms, hooks |171| Integration | Vitest + Supabase test project | API routes, Server Actions, DB queries, RLS policies |172| E2E | Playwright | Full user journeys: signup → use feature → logout |173| Component | Vitest + Testing Library | User interaction, form submission, error states |174175### React Testing Library Philosophy (from the repo)176> "The more your tests resemble the way your software is used, the more confidence they can give you."177178- Query by role, label, text — not by class, ID, or test-id179- Fire real events (`userEvent.click`) not synthetic (`fireEvent.click`)180- Assert on what the user sees, not on component internals181- If you can't test something without accessing component internals, your component API needs refactoring182183---184185## Database/RLS Test Patterns186187```ts188// Test RLS policies directly189describe('RLS: users table', () => {190 it('user can only read own profile', async () => {191 const userA = await createTestUser()192 const userB = await createTestUser()193194 const clientA = createClientAs(userA)195 const { data } = await clientA.from('profiles').select('*')196197 expect(data).toHaveLength(1)198 expect(data[0].id).toBe(userA.id)199 // userB's profile is not visible200 })201202 it('unauthenticated user cannot read profiles', async () => {203 const anonClient = createAnonClient()204 const { data, error } = await anonClient.from('profiles').select('*')205 expect(data).toHaveLength(0) // RLS blocks everything206 })207})208```209210## Sources211- testing-library/react-testing-library documentation and guiding principles212- vitest-dev/vitest configuration and best practices213- Kent C. Dodds: Testing Implementation Details214- Supabase testing documentation215216## Changelog217- 2026-03-21: Initial skill — test review for Next.js + Supabase
Run npx get-skill add nickgallick/testing-review in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Test coverage and quality review — what needs tests, test quality assessment, anti-patterns, and the testing pyramid for Next.js + Supabase applications. It is listed under Web & Frontend on SkillMD.
SkillMD's automated safety review verdict for this skill is PASS. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. Capability flags: reads secrets. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
nickgallick (@nickgallick) published this skill. Their other Agent Skills are listed on their SkillMD profile.