Testing / Playwright Interview questions
When should you use component testing in Playwright?
Playwright Component Testing mounts an individual UI component (React, Vue, Svelte) in isolation inside a real browser, rather than rendering the whole application through routing and full page loads.
import { test, expect } from '@playwright/experimental-ct-react'; import { Counter } from './Counter'; test('increments on click', async ({ mount }) => { const component = await mount(<Counter />); await component.getByRole('button').click(); await expect(component).toHaveText('1'); });
It's the right choice when you want to verify a component's behavior and rendering in real browser conditions (unlike a pure unit test with a simulated DOM) but don't want the overhead, setup, and flakiness surface area of navigating a full application to reach that component. It sits between unit tests and full end-to-end tests: faster and more isolated than e2e, but more realistic than JSDOM-based unit testing since it runs in an actual browser engine.
More Related questions...