TypeScript · testing
no-sleep-in-test-body
eslint:no-sleep-in-test-body Disallow a fixed timed sleep directly in a test body; it flakes under CI load. Synchronize on the signal or use fake timers.
- Default
- error
- Fix
- none
- Languages
- typescript
Why
Wall-clock delays make test correctness depend on scheduler and machine speed.
Fix
Await the observable signal or advance deterministic fake timers.
Before / after
Executed by this rule’s unit tests.
Before
Do not wait for wall-clock time
it('retries', async () => { await sleep(50); expect(done()).toBe(true); }); After
Advance time deterministically
it('retries', async () => { vi.useFakeTimers(); const result = retry(); await vi.advanceTimersByTimeAsync(50); await result; }); Limits
- Only fixed nonzero sleeps directly inside test and per-test hook callbacks are checked; nested fakes and parameterized delays are excluded.
Files
**/*.test.***/*.spec.***/tests/****/__tests__/**Message IDs
noSleepInTestBody