unit-test-quality-standards: a zero-delay setTimeout yield is reported as a real-timer wait
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- testing
Research direction
The check lives in waitsOnRealTimer in src/utils/testing/async-test-analyzer/async-test-analyzer-configuration.ts (around line 146), which matches TIMER_CALL (line 136) without reading the delay argument. Start by reading how that matcher captures the call, then add a case where a missing or literal 0 delay is not counted. Done when the reproduction in src/sum.spec.ts no longer reports a violation, while setTimeout(resolve, 1200) and non-literal delays still do.
Written by the indexing model from the issue text.
Description
Version: 8.0.1 (tag v8.0.1)
Law: unit-test-quality-standards (Unit Test Quality Standards), "setTimeout usage without fake timers may cause test flakiness"
What happens
AsyncTestAnalyzerConfiguration.waitsOnRealTimer (src/utils/testing/async-test-analyzer/async-test-analyzer-configuration.ts:146) counts every setTimeout( (TIMER_CALL, :136) in a file without useFakeTimers( and without clearTimeout(handle). The delay argument is not read.
Reproduction
it('adds after the pending microtasks and one macrotask have run', async () => {
await new Promise((resolve) => setTimeout(resolve));
expect(sum(1, 2)).toBe(3);
});
laws.enabled { "Unit Test Quality Standards": true }, typescript installed:
1. Unit Test Quality Standards [2 violations] (Score: 80/100)
• setTimeout usage without fake timers may cause test flakiness in src/sum.spec.ts
What I ruled out
The same violation is produced for setTimeout(resolve, 0) and for setTimeout(resolve, 1200): the message is identical, so a reader cannot tell a yield from a sleep.
Why it matters
await new Promise((r) => setTimeout(r)) yields one macrotask; it does not wait on wall-clock time and is not a flakiness risk. In a large codebase such yields are common and they drown the few real waits, which are the ones the law is for.
Suggested direction
- Do not count a call with no delay argument or a literal
0. - Keep counting non-zero literal delays and non-literal delays.
- Optionally put the delay in the message (
setTimeout(…, 1200) without fake timers).
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 0
- Avg merge
- 2h 36m
- Merged PRs (30d)
- 168
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rule-Of-Code/RoC
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Rule-Of-Code/RoC#547 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Rule-Of-Code/RoC#506 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Rule-Of-Code/RoC#501 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 62/100
Rule-Of-Code/RoC#563 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 50/100
Rule-Of-Code/RoC#562 ·
Maintainers usually reply within 1 day
All issues in Rule-Of-Code/RoC
Similar issues
-
bug done
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neavo/LinguaGacha#1124 ·
Maintainers usually reply within 1 day
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsPossibly taken @fullsend-ai-coder claimed this today. Opene2e-failure ready-to-code
Difficulty 2/5 Under an hour Newbie friendliness 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
brylie/mission-island#225 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google-gemini/gemini-cli#30412 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day