Playwright did not expect test(): Fix imports

updated November 12, 2026

Your test stops while Playwright reads the config. Open the first file from your project in the stack trace. If the config imports a test file, remove that import. Put any settings both files need in a module that declares no tests. Then run:

npx playwright test --list

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

Our config imported tests/cart.spec.ts. Importing it ran its top-level test() while Playwright was still reading settings. The runner printed:

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

Once we removed the import, Playwright found the same test during collection. Collection is the step where the runner loads test files and records their test names.

When the same test file loads The config imports cart.spec.ts while Playwright reads settings. Its test call fails. When the runner loads cart.spec.ts during collection, it registers the test. The config imports the spec cart.spec.ts: too early The runner collects the spec cart.spec.ts: test registered

A helper loads another copy of Playwright Test

If the stack points into a helper package, run npm ls @playwright/test. Our project used 1.65.0. A helper that declared tests loaded its own copy, 1.64.0. In the helper's package.json, we moved @playwright/test from dependencies to peerDependencies and allowed 1.65.0. The helper then shared the project's runner, and its test passed.

Playwright Test did not expect test.describe() to be called here.

Our config called test.describe() and the error named that function instead. Move the group into a test file. Keep the group callback synchronous. In another run, declaring a test after an await in that callback produced the test() error. Put awaited work inside the test or a setup hook.

We checked Playwright Test 1.65.0 on macOS 15.4.1 and Debian 12 on 10 November 2026. The config import failed in JavaScript and TypeScript with CI=1 and with CI unset.

Put it into practice

Solve a graded problem: write a test, and we check it would catch a real bug.

Browse the problems →

Learn this in full

Reading about a problem is not the same as fixing one. Pick a lecture or a practice problem and write the test yourself.

Keep reading