Playwright now supports testing React, Vue, and Svelte components in isolation.
import { test, expect } from '@playwright/experimental-ct-react';
import Button from './Button';
test('button click', async ({ mount }) => {
let clicked = false;
const component = await mount(
<Button onClick={() => clicked = true}>Click Me</Button>
);
await component.click();
expect(clicked).toBe(true);
});
This runs in a real browser, unlike Jest/JSDOM, catching CSS/styling issues that unit tests miss.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.