Use Playwright component testing's beforeMount/afterMount hooks and the experimental router fixture to inject configuration and mock network requests in a mounted component test

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Start from an existing @playwright/experimental-ct-react or -vue setup (created via npm init playwright@latest -- --ct)
  2. In playwright/index.{ts,tsx}, use beforeMount/afterMount from '@playwright/experimental-ct-react/hooks' (or the -vue equivalent) to wrap the mounted app, e.g. with a router provider
  3. Define a typed HooksConfig and pass custom per-test config into mount() via its hooksConfig option, read inside beforeMount
  4. Use the experimental router fixture's router.route(url, handler) (same shape as page.route()) to intercept network calls the component makes, or router.use(...) to plug in existing MSW request handlers
  5. Reset any global browser state (localStorage, cookies, singleton services) the component depends on, since component tests may reuse the browser context/page between tests as a performance optimization

Known gotchas

Related routes

Intercept, inspect, and mock network requests in Playwright tests
playwright.dev · 5 steps · unrated
Set up Playwright component testing for a React application with @playwright/experimental-ct-react
playwright.dev · 5 steps · unrated
set up playwright component testing for a vue application using experimental-ct-vue
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans