QA-TEST-004 — Hard sleep in test
Generated from the rule registry. Get the same detail from the CLI with
mjolnir explain QA-TEST-004.
| Field | Value |
|---|---|
| Severity | warning |
| Confidence | high |
| Tier | extended |
| Measured FP rate | 30% (n=20) |
| Evidence level | E2 |
| QA impact | Flaky-test risk (FLAKY-RISK) |
| False-positive risk (author estimate) | low |
| Autofix available | no |
| Languages | typescript, javascript |
| Frameworks | jest, vitest, playwright, mocha |
| Detection strategy | LEXICAL (regex pattern + behavioral wait-shape matching) |
| Introduced in | v0.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):
| Repo | Occurrences |
|---|---|
| appsmithorg-appsmith | 7 |
| dubinc-dub | 7 |
| getsentry-sentry | 11 |
| github-docs | 4 |
| grafana-grafana | 164 |
| puppeteer-puppeteer | 3 |
| SeleniumHQ-selenium | 2 |
| streamlit-streamlit | 13 |
| sveltejs-kit | 10 |
| tanstack-query | 157 |
| vercel-next-js | 140 |
| vitejs-vite | 8 |
| vitest-dev-vitest | 77 |
| withastro-astro | 32 |
| yarnpkg-berry | 3 |