Lab 11: Testing Architecture
Overview
Step 1: Vitest Setup
// vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true, // No import needed for describe/test/expect
environment: 'node', // or 'jsdom' for browser-like
typecheck: {
enabled: true, // Run type tests with tsc
tsconfig: './tsconfig.test.json',
},
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
thresholds: { lines: 80, functions: 80, branches: 70 },
},
setupFiles: ['./src/test/setup.ts'],
},
});Step 2: Type-Level Tests with expectTypeOf
Step 3: MSW — Typed Request Handlers
Step 4: Typed Test Fixtures — Factory Pattern
Step 5: Property-Based Testing with fast-check
Step 6: Integration Test with Dependency Injection
Step 7: Snapshot Testing with Type Checks
Step 8: Capstone — Property-Based Tests
Summary
Tool
Purpose
TypeScript Benefit
Last updated
