Test the behavior users depend on
Choose an observable outcome and test it through roles and labels. For example, submit invalid input and assert the visible error, rather than checking private state or CSS classes. Use small module tests for rules and a few browser tests for the critical journeys. The snippet assumes your local app has an Email field and a Save button; adapt it to your actual interface.
#testing#shipping
typescript
import { test, expect } from '@playwright/test';
test('rejects an invalid email', async ({ page }) => {
await page.goto('/profile'); // configure baseURL for your test server
await page.getByLabel('Email', { exact: true }).fill('invalid');
await page.getByRole('button', { name: 'Save', exact: true }).click();
await expect(page.getByRole('alert')).toContainText('valid email');
});Sources
Verified 2026-09-30