The Testing Trophy: Kent C. Dodds' Case for Integration Tests

The Testing Trophy: Kent C. Dodds' Case for Integration Tests

If you've worked in software long enough, someone has probably handed you a triangle and told you to put most of your tests at the bottom. The test pyramid — lots of unit tests, fewer integration tests, even fewer end-to-end tests — has been the default mental model for test strategy for over a decade.

Kent C. Dodds disagrees. And he has a trophy to show for it.

The testing trophy flips the emphasis. Instead of maximizing unit tests, it argues that integration tests give you the best return on investment — the most confidence per dollar of engineering time. This post explains the model, why it matters, and how to apply it in a real JavaScript or React project.

What the Testing Trophy Looks Like

The trophy has four layers, from bottom to top:

  1. Static analysis — the wide base
  2. Unit tests — a smaller layer above that
  3. Integration tests — the widest section, the "body" of the trophy
  4. End-to-end tests — a narrow top

The shape matters. The widest layer is integration tests, not unit tests. Dodds' argument is that integration tests give you the highest confidence that your code works as users actually experience it, without the fragility of full browser automation.

The Problem with Pyramid-Heavy Unit Testing

Unit tests are fast and precise. You isolate a function, pass it inputs, assert on outputs. That sounds ideal — but it creates a hidden cost: your tests can all pass while your application is completely broken.

Classic example: you have a calculateTotal() function with 100% unit test coverage. The tests all pass. But the component that calls calculateTotal() passes arguments in the wrong order. The integration fails. The user sees a broken cart. Your tests told you nothing.

The more you unit test in isolation, the more mocking you need. The more mocking you need, the further your tests drift from reality. Tests that mock everything test nothing except your mock configuration.

Static Analysis: The Underrated Base

Before any test runs, static analysis is already catching bugs. In a modern JavaScript project, the static layer includes:

# TypeScript — catches type errors before runtime
npx tsc --noEmit

# ESLint — catches code quality issues
npx eslint src/

# Prettier — catches formatting inconsistencies
npx prettier --check src/

# Import verification (via bundler or eslint-plugin-import)
npx eslint --rule 'import/no-unresolved: error' src/

TypeScript alone eliminates an entire category of integration failures — wrong argument types, missing properties, calling methods that don't exist. It's not a test, but it's the cheapest safety net you have.

Configure your CI to run static checks before any test suite:

# .github/workflows/ci.yml
jobs:
  static:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npx tsc --noEmit
      - run: npx eslint src/
  
  tests:
    needs: static
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test

Static checks are your first and fastest feedback loop. They catch the class of bugs that don't need any runtime at all.

Unit Tests: Small, Fast, Focused

Unit tests still belong in the trophy — they're just not the majority. Use them for:

  • Pure functions with complex logic (parsers, formatters, algorithms)
  • Edge cases that are hard to trigger through UI
  • Error handling paths that would require complex setup to reach otherwise

A good unit test for a pure function in JavaScript:

// utils/price.js
export function formatPrice(cents, currency = 'USD') {
  if (typeof cents !== 'number' || isNaN(cents)) {
    throw new TypeError(`Expected number, got ${typeof cents}`);
  }
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency,
  }).format(cents / 100);
}
// utils/price.test.js
import { formatPrice } from './price';

describe('formatPrice', () => {
  it('formats cents to USD string', () => {
    expect(formatPrice(1999)).toBe('$19.99');
  });

  it('handles zero', () => {
    expect(formatPrice(0)).toBe('$0.00');
  });

  it('supports other currencies', () => {
    expect(formatPrice(1000, 'EUR')).toBe('€10.00');
  });

  it('throws on non-number input', () => {
    expect(() => formatPrice('19.99')).toThrow(TypeError);
  });
});

This is the right scope for a unit test: pure logic, no DOM, no network, no other modules. Fast, reliable, deterministic.

Integration Tests: The Trophy's Widest Zone

This is where Kent C. Dodds puts the most emphasis, and where Testing Library shines. An integration test renders a real component tree, simulates real user interactions, and asserts on what the user actually sees — without running a real browser.

The key distinction from an E2E test: you're still using jsdom (or happy-dom) in Jest/Vitest, so there's no Selenium, no Playwright, no network. But you're not mocking child components either. The whole component tree renders and runs.

Here's a realistic integration test for a checkout form:

// CheckoutForm.test.jsx
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { CheckoutForm } from './CheckoutForm';
import { server } from '../mocks/server'; // MSW server
import { http, HttpResponse } from 'msw';

describe('CheckoutForm', () => {
  it('submits an order and shows confirmation', async () => {
    const user = userEvent.setup();
    render(<CheckoutForm />);

    // Fill out the form
    await user.type(screen.getByLabelText(/email/i), 'buyer@example.com');
    await user.type(screen.getByLabelText(/card number/i), '4111111111111111');
    await user.type(screen.getByLabelText(/expiry/i), '12/26');
    await user.type(screen.getByLabelText(/cvv/i), '123');

    // Submit
    await user.click(screen.getByRole('button', { name: /place order/i }));

    // Assert confirmation appears
    await waitFor(() => {
      expect(screen.getByText(/order confirmed/i)).toBeInTheDocument();
    });
  });

  it('shows validation errors for empty fields', async () => {
    const user = userEvent.setup();
    render(<CheckoutForm />);

    await user.click(screen.getByRole('button', { name: /place order/i }));

    expect(screen.getByText(/email is required/i)).toBeInTheDocument();
    expect(screen.getByText(/card number is required/i)).toBeInTheDocument();
  });

  it('shows API error when payment fails', async () => {
    server.use(
      http.post('/api/orders', () =>
        HttpResponse.json({ error: 'Card declined' }, { status: 402 })
      )
    );

    const user = userEvent.setup();
    render(<CheckoutForm />);

    await user.type(screen.getByLabelText(/email/i), 'buyer@example.com');
    await user.type(screen.getByLabelText(/card number/i), '4000000000000002');
    await user.type(screen.getByLabelText(/expiry/i), '12/26');
    await user.type(screen.getByLabelText(/cvv/i), '123');
    await user.click(screen.getByRole('button', { name: /place order/i }));

    await waitFor(() => {
      expect(screen.getByText(/card declined/i)).toBeInTheDocument();
    });
  });
});

Notice what's happening here:

  • The full CheckoutForm component tree renders — including child components for card input, validation, error display
  • User interactions use userEvent (not fireEvent) for realistic event sequences
  • Network calls are intercepted with MSW, not mocked at the module level
  • Assertions are on visible text, not internal state or implementation details

This test would catch the "wrong argument order" bug that pure unit tests miss, because it tests the integration between form state, validation logic, submission handler, and UI feedback.

Setting Up MSW for Integration Tests

Mock Service Worker (MSW) is the recommended tool for intercepting network requests in integration tests. It works at the network level, not the module level — so your actual fetch/axios calls are made, then intercepted.

// src/mocks/handlers.js
import { http, HttpResponse } from 'msw';

export const handlers = [
  http.post('/api/orders', () => {
    return HttpResponse.json({ id: 'ord_123', status: 'confirmed' });
  }),

  http.get('/api/products', () => {
    return HttpResponse.json([
      { id: 1, name: 'Widget', price: 999 },
      { id: 2, name: 'Gadget', price: 1499 },
    ]);
  }),
];
// src/mocks/server.js
import { setupServer } from 'msw/node';
import { handlers } from './handlers';

export const server = setupServer(...handlers);
// src/setupTests.js
import { server } from './mocks/server';

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

Now your integration tests run real component logic against realistic (but controlled) API responses. You can override specific handlers per test for error scenarios.

End-to-End Tests: Narrow but Critical

E2E tests in the trophy are intentionally few. They should cover only the scenarios where browser-level behavior matters and the cost is justified:

  • Complete happy-path flows (signup → purchase → confirmation)
  • Scenarios involving real cookies, localStorage, or browser APIs
  • Critical paths where a production failure would cause maximum business damage

In Playwright:

// e2e/checkout.spec.ts
import { test, expect } from '@playwright/test';

test('complete purchase flow', async ({ page }) => {
  await page.goto('/products');
  await page.click('[data-testid="add-to-cart-1"]');
  await page.click('[data-testid="checkout-button"]');

  await page.fill('[name="email"]', 'test@example.com');
  await page.fill('[name="card-number"]', '4111111111111111');
  await page.fill('[name="expiry"]', '12/26');
  await page.fill('[name="cvv"]', '123');

  await page.click('[type="submit"]');

  await expect(page.locator('text=Order confirmed')).toBeVisible();
});

Keep this layer small. Each E2E test that passes gives you the highest confidence, but also takes the most time, costs the most to maintain, and fails the most often for unrelated reasons (network flakiness, timing issues, environment differences).

Applying the Trophy to Your Project

A practical starting point for a React project:

Layer Tool Target
Static TypeScript + ESLint 0 errors, enforced in CI
Unit Vitest or Jest Pure functions, complex algorithms
Integration Testing Library + MSW All user-facing features
E2E Playwright 5-10 critical flows max

The ratio question — how many integration vs unit tests — is less important than the principle: write tests at the level where failure would cost you the most confidence. For most UI features, that's integration level.

If you find yourself writing a unit test that requires mocking five dependencies, that's a signal to move up a level. If your integration test suite takes 15 minutes to run, look for candidates to move down a level.

The Key Insight

The testing trophy isn't about dismissing unit tests. It's about recognizing that confidence in your software comes from testing how pieces work together, not how each piece works in isolation.

When a user clicks "Place Order," they don't care if calculateTotal() is unit-tested. They care if the order goes through. Your tests should reflect that priority.

Build a wide integration layer. Back it with a strong static analysis base. Add unit tests where logic is complex enough to deserve focused coverage. Use E2E tests for your most critical flows. That's the trophy shape — and it's the shape of a test suite you can trust.

Read more

Start now free