DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Articles
  3. Frontend Engineering
  4. React Testing: Unit, Integration, and E2E Strategies
XLinkedInReddit
MediumFrontend Engineering

React Testing: Unit, Integration, and E2E Strategies

D
DevPrep Team
February 10, 2026·1 min read·0
Table of Contents
  • The Testing Pyramid
  • Unit Tests with React Testing Library
  • Testing Hooks
  • Integration Tests
  • What NOT to Test
  • Testing Best Practices

Testing at Google follows the testing pyramid: many unit tests, fewer integration tests, and minimal E2E tests.

The Testing Pyramid

        /  E2E  \\        ← Few, slow, expensive
       / Integration \\   ← Moderate amount
      /    Unit Tests    \\ ← Many, fast, cheap

Unit Tests with React Testing Library

import { render, screen, fireEvent } from "@testing-library/react";
import { Counter } from "./Counter";

test("increments counter on click", () => {
  render(<Counter />);
  const button = screen.getByRole("button", { name: /increment/i });
  fireEvent.click(button);
  expect(screen.getByText("Count: 1")).toBeInTheDocument();
});

Testing Hooks

import { renderHook, act } from "@testing-library/react";
import { useCounter } from "./useCounter";

test("useCounter increments", () => {
  const { result } = renderHook(() => useCounter());
  act(() => result.current.increment());
  expect(result.current.count).toBe(1);
});

Integration Tests

test("user can search and filter results", async () => {
  // Mock API
  server.use(
    rest.get("/api/products", (req, res, ctx) => {
      const q = req.url.searchParams.get("q");
      return res(ctx.json(products.filter(p => p.name.includes(q))));
    })
  );

  render(<ProductSearch />);
  
  await userEvent.type(screen.getByRole("searchbox"), "laptop");
  await userEvent.click(screen.getByRole("button", { name: /search/i }));
  
  expect(await screen.findAllByRole("listitem")).toHaveLength(3);
});

What NOT to Test

  • Implementation details (state values, internal methods)
  • Third-party library internals
  • CSS styling (use visual regression tools instead)
  • Constants and configuration

Testing Best Practices

  • Test behavior, not implementation
  • Use screen.getByRole over getByTestId
  • Prefer userEvent over fireEvent (closer to real user behavior)
  • One assertion per behavior, not per test
  • Use MSW for API mocking — it works at the network level

Related Articles

MediumFrontend Engineering

System Design #12: Design a Multi-Step Form Wizard

7 min read
MediumFrontend Engineering

Mastering Senior-Level JavaScript Interview Concepts

2 min read
MediumFrontend Engineering

System Design #9: Design a Collaborative Text Editor

9 min read

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Table of Contents

  • The Testing Pyramid
  • Unit Tests with React Testing Library
  • Testing Hooks
  • Integration Tests
  • What NOT to Test
  • Testing Best Practices

Series

View all Frontend Engineering articles →

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.