Skip to content

QA-PW-101 — Hard sleep via waitForTimeout ​

← Back to the rule catalog

Generated from the rule registry. Get the same detail from the CLI with mjolnir explain QA-PW-101.

FieldValue
Severityerror
Confidencehigh
Tierextended
Measured FP rate0% (n=20)
Evidence levelE2
QA impactFlaky-test risk (FLAKY-RISK)
False-positive risk (author estimate)low
Autofix availableno
Languagestypescript, javascript
Frameworksplaywright
Detection strategyLEXICAL
Introduced inv0.3.0

Why this fails in production ​

page.waitForTimeout(N) waits a fixed wall-clock duration regardless of the actual state of the page — it has no idea whether the element it's really waiting for appeared in 50ms or will never appear at all. Too short for a slow CI runner (shared hardware, cold caches, resource contention under a parallel test matrix) and the test fails intermittently; too long and the whole suite's wall-clock time balloons for no correctness benefit. The fix (await expect(locator).toBeVisible(), or an equivalent condition-wait) is not slower in the success case and is actually faster on average, because it proceeds the instant the condition is true instead of always waiting the full fixed duration.

What gets flagged (real detector output) ​

`waitForTimeout()` hard sleep.

Example from this rule's own must-fire fixture: tests/fixtures/QA-PW-101/must-fire/sleepy.spec.ts

The fix ​

Replace with a web-first assertion (await expect(locator).toBeVisible()) or locator.waitFor().

Confirmed NOT to fire on the corresponding clean pattern ​

Verified against tests/fixtures/QA-PW-101/must-not-fire/clean.spec.ts — a legitimate, similar-looking pattern this rule correctly leaves alone.

Corpus-measured false-positive risk ​

Real occurrence counts from npm run corpus:audit against actively-maintained OSS repos — reproduce yourself, don't just trust this table (see the false-positive audit):

RepoOccurrences
github-docs10
grafana-grafana17
nextauthjs-next-auth4
positive-fixtures1
sveltejs-kit62
vercel-next-js4
vitest-dev-vitest2
withastro-astro4

Released under the MIT License.