Playwright · Reliable end-to-end tests

Can Playwright test components in isolation?

Hardcomponent testingreactmountUpdated Oct 2026
Quiz this track

Short answer

Yes, through experimental component testing: mount a component in a real browser with @playwright/experimental-ct-react and assert on rendered output. It is separate from the standard E2E runner.

Playwright component testing mounts a component directly in a real browser instead of navigating through the whole application. It gives you the browser engine, locators and assertions of Playwright with a much smaller surface than a full page.

tsx
import { test, expect } from "@playwright/experimental-ct-react";
import { Button } from "../../src/components/Button";

test("shows a loading label", async ({ mount }) => {
  const component = await mount(<Button loading>Save</Button>);

  await expect(component).toContainText("Saving...");
  await expect(component).toBeDisabled();
});
The mount fixture renders the component in a real browser and returns a locator for its root.

How it fits

  • Requires the experimental component-testing package for your framework
  • Uses a separate config, commonly playwright-ct.config.ts
  • Supports React, Vue, Svelte and Solid through framework-specific packages
  • Runs in Chromium, Firefox or WebKit with the normal locator API
  • Is still marked experimental, so check the current documentation before adopting it widely

Component tests are a good fit for interactive widgets with complex internal state: a combobox, a date picker or a data grid. They are a poor fit for things that only make sense with routing, authentication and a real backend. For pure rendering and logic, a fast unit or browser-mode test may still be cheaper.

Component testing is not the same as end-to-end testing, and it does not replace it. It reduces the cost of testing component behaviour in a browser, but the critical user journeys still need full-page coverage.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1How is component testing different from end-to-end testing?
  2. 2What config does component testing use?
  3. 3When would you choose a unit test instead?
  4. 4Why is the experimental status important?

Say it in the interview

Playwright can mount a component in a real browser through its experimental component-testing packages. I use the mount fixture, then assert with the same locators and web-first assertions as an E2E test. It is a good fit for complex interactive widgets, not for flows that need routing, authentication and a real backend. Because it is experimental, I check the current API before building a large suite around it.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Playwright mock interview and get scored feedback on depth, clarity and confidence.