The Testing Trophy
Focus more on integration tests, less on unit tests, and a thin layer of E2E.
Unit Testing with Vitest
import { describe, it, expect } from "vitest";import { calculateReadingTime } from "./utils";describe("calculateReadingTime", () => { it("calculates reading time", () => { expect(calculateReadingTime("Hello world")).toBe(1); });});
Integration Testing with Testing Library
import { render, screen, userEvent } from "@testing-library/react";test("adds a todo", async () => { const user = userEvent.setup(); render(<TodoApp />); await user.type(screen.getByRole("textbox"), "Buy groceries"); await user.click(screen.getByRole("button", { name: /add/i })); expect(screen.getByText("Buy groceries")).toBeInTheDocument();});
E2E Testing with Playwright
import { test, expect } from "@playwright/test";test("user can sign up", async ({ page }) => { await page.goto("/signup"); await page.fill('[name="email"]', "test@example.com"); await page.click('button[type="submit"]'); await expect(page).toHaveURL("/dashboard");});
Testing Strategy
Unit tests: pure functions, utilities (20%)
Integration tests: components, hooks, forms (60%)
E2E tests: critical paths only (20%)
Test behavior, not implementation
Mock APIs, not internal modules