Fixed sleep in a test
This is how the comment reads inline, under the flagged line.
Why it matters
Sleeps make tests slow and flaky at once: they guess how long something takes instead of waiting for it.
What to do
Wait for the condition (waitFor, an event, a polled assertion) or use fake timers.
Examples
await sleep(500); expect(list).toHaveLength(3);
await waitFor(() => expect(list).toHaveLength(3));
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: Test files only. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
await sleep(500);
tests/test_a.py
import time time.sleep(1)
Left alone
await waitFor(() => done);
Research
Fixed sleeps and `setTimeout` waits, in tests and in shipped code. It is slow when the state is ready and flaky when it is not.
- Test smell catalog
- AI slop in developer posts (arXiv)
- owner's code bar
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"sleep-in-test"
],
"severity": {
"sleep-in-test": "low"
}
}
}
await sleep(5waits a fixed time. Too short on a slow CI box, wasted time everywhere else.