Query native roles, labels, visible text, and state instead of internal class names or component function calls.
Assert the user-visible outcome: selected tab, open dialog, changed field, announced status, or returned focus.
Prefer real Pixxl components over mocks; mock only browser or application boundaries that cannot run deterministically.
Keep each test readable as a behavior contract and cover empty, disabled, invalid, loading, and error states when supported.
@pixxl-tools/components/testing has the shims a jsdom or happy-dom suite needs to render Pixxl components, so a site’s setup file does not carry its own. Framework-agnostic: call them from a Vitest or Jest setup file.
installBrowserShims({ prefersDark, prefersReducedMotion, matches, storage }) sets matchMedia (answering only the queries you enable, or your matches(query) function), adds no-op ResizeObserver and IntersectionObserver where they are missing, stubs scrollTo and scrollIntoView, and with storage: true replaces localStorage and sessionStorage with in-memory ones.
mockMatchMedia(options) changes the answers inside one test, e.g. mockMatchMedia({ prefersDark: true }) before rendering a ThemeSwitcher.
resetBrowserState() clears both storages, every cookie the page can read and the theme attributes, so a theme, locale or consent choice does not leak into the next test. createMemoryStorage() returns a Storage for code that takes one.
// tests/setup.ts
import { afterEach } from "vitest";
import { cleanup } from "@testing-library/react";
import { installBrowserShims, resetBrowserState } from "@pixxl-tools/components/testing";
installBrowserShims(); // matchMedia, ResizeObserver, IntersectionObserver, scrollTo, scrollIntoView
afterEach(() => {
cleanup();
resetBrowserState(); // storages, cookies, data-theme / data-accent / data-density on <html>
});Controlled test: pass value/open, handle the change callback, rerender with the new value, and assert the UI follows host state.
Uncontrolled test: pass defaultValue/defaultOpen, interact, and assert the component owns the update.
Verify callbacks expose semantic values, not internal event order.
Test that state remains stable when unrelated props or parent state rerender.
Tab through controls in document order and exercise Enter, Space, Escape, and arrow keys where the component contract uses them.
Verify dialogs and dismissable layers move focus intentionally and restore it to the trigger.
Check composite controls expose current selection/expanded state to the accessibility tree.
Do not replace keyboard checks with click-only tests.
Exercise phone, tablet, desktop, and wide-desktop widths with long localized labels and dense content.
Check wrapping, min-width containment, overflow, sticky regions, touch targets, and mobile/desktop alignment changes.
Use visual baselines for real appearance changes, but pair them with semantic assertions.
Never approve a changed baseline until the rendered difference is understood and intended.
Architecture checks should reject framework imports, runtime dependencies, unprefixed CSS, and raw visual values outside token definitions.
Metadata/public API checks must fail when a new component export lacks documentation data.
pnpm exec playwright test -c tests/playwright.config.ts --project=component
pnpm exec tsc -p tsconfig.json --noEmit --pretty false --incremental false
pnpm exec eslint components tests/component/components --max-warnings=0
pnpm --filter @pixxl-tools/components run build