Skip to content

QA-TEST-004 — Hard sleep in test ​

← Back to the rule catalog

Generated from the rule registry. Get the same detail from the CLI with mjolnir explain QA-TEST-004.

FieldValue
Severitywarning
Confidencehigh
Tierextended
Measured FP rate30% (n=20)
Evidence levelE2
QA impactFlaky-test risk (FLAKY-RISK)
False-positive risk (author estimate)low
Autofix availableno
Languagestypescript, javascript
Frameworksjest, vitest, playwright, mocha
Detection strategyLEXICAL (regex pattern + behavioral wait-shape matching)
Introduced inv0.1.0

Why this fails in production ​

Fixed sleeps make tests both slow and flaky — they guess at timing instead of waiting for state.

What gets flagged (real detector output) ​

Hard sleep: `page.waitForTimeout(`.

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

The fix ​

Replace with a condition wait: await expect(locator).toBeVisible().

Confirmed NOT to fire on the corresponding clean pattern ​

Verified against tests/fixtures/QA-TEST-004/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
appsmithorg-appsmith7
dubinc-dub7
getsentry-sentry11
github-docs4
grafana-grafana164
puppeteer-puppeteer3
SeleniumHQ-selenium2
streamlit-streamlit13
sveltejs-kit10
tanstack-query157
vercel-next-js140
vitejs-vite8
vitest-dev-vitest77
withastro-astro32
yarnpkg-berry3

Released under the MIT License.