Playwright 1.20: Component Testing

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.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.