Playwright error

Error: Playwright Test did not expect test() to be called here

Playwright found a test() call somewhere it can't register one. It's almost always two copies of @playwright/test, or a spec file importing another spec file.

Published

Why this happens

How to fix it

  1. Run `npm ls @playwright/test` and dedupe until exactly one version is listed
  2. Move shared helpers and fixtures out of `*.spec.ts` files into a plain module (e.g. `fixtures.ts`) and import from there
  3. Keep `test()` calls at the top level of the spec file or inside `test.describe()`, never inside another test or an async callback
  4. Import `test` and `expect` only from `@playwright/test` (or your own fixtures file that extends it)

Example


              // Bad: login.spec.ts imports a helper that lives in another spec file
import { loginAs } from './checkout.spec';

// Good: helpers live in a plain module, not a spec file
// helpers/auth.ts
export async function loginAs(page: Page, user: string) { /* ... */ }

// login.spec.ts
import { loginAs } from './helpers/auth';