Course contentsShow
← React
Lesson 2123 of 2,39647. Testing Patterns and Best PracticesFree lesson

When Container/Presentational Split Doesn't Matter

Test the connected component as users see it, not the presentational component with mocked props.

When Container/Presentational Split Doesn't Matter

You'll learn why connected/container components should be tested as integrated units, not by mocking their presentational parts.

The Old Pattern, The New Reality

For years, React developers split components into "containers" (connected to Redux, context, or data) and "presentational" (pure, props-only). This led to a testing pattern: mock the data layer, pass fake props to the presentational component, assert it renders correctly.

But here's the insight: your users don't interact with presentational components. They interact with the connected version. Testing the presentational component in isolation tells you nothing about whether the container wires data correctly.

The Testing Philosophy Shift

Think of a restaurant meal. You wouldn't test the ingredients separately and assume the finished dish works. You taste the dish as served.

Similarly, test components as users encounter them: already connected, already wrapped in providers, pulling real (or realistically mocked) data. If a component is connected to Redux, render it with a test store. If it uses useContext, render it with a test provider. If it fetches data, let it fetch (with MSW handling the response).

Why the Split Doesn't Matter

When you test the connected component:

  • You verify the integration: does the selector work? Does the dispatch call the right action?
  • Your tests survive refactoring: merge container and presentational? Tests still pass.
  • You catch real bugs: typos in mapStateToProps, wrong context key, broken hooks.

Testing the presentational component alone? It passes even if the container is completely broken.

The Practical Approach

Don't export the presentational component separately just for testing. Export the connected version. Render it with realistic context (test store, test providers). Assert what appears on screen. That's what matters.

Key Takeaway: Test the component as users see it—connected, integrated, and complete—not the artificial presentational split that exists only in your source code.