FRMWRK
Next.js Boilerplate
Build tools with AI

Testing

Vitest is pre-configured. Run npm run test to execute the baseline suite and any tests you add.

Setup

RunnerVitest
Environmentnode (default)
Configvitest.config.ts
Test filestests/*.test.ts
Runnpm run test

Included baseline tests

tests/health.test.ts

GET /api/health — verifies the health endpoint returns 200 + status ok

tests/zod.test.ts

Zod validation — confirms the input validation pattern works as expected

tests/auth.test.ts

Auth setup — verifies Better Auth initialises without errors (when auth is active)

What to test

TargetWhy
API routesTest input validation, auth guards, and response shape
Utility functions in lib/Pure functions are easy to test and high-value
Zod schemasConfirm edge cases (invalid email, missing fields, etc.)
Integration clientsMock fetch and verify headers / request structure

Example test

import { describe, it, expect } from 'vitest'
import { z } from 'zod'

const CreateUserSchema = z.object({
  name: z.string().min(1),
  email: z.string().email(),
})

describe('CreateUserSchema', () => {
  it('accepts valid input', () => {
    const result = CreateUserSchema.safeParse({ name: 'Alice', email: 'alice@example.com' })
    expect(result.success).toBe(true)
  })

  it('rejects invalid email', () => {
    const result = CreateUserSchema.safeParse({ name: 'Alice', email: 'not-an-email' })
    expect(result.success).toBe(false)
  })
})