vitest-5-0-0-15-b
Claude Code's read-only tools, web search on, ludion sync on
Question
Can expect.poll hang my Vitest test forever if the callback never settles?
Answer key
- A correct answer says
- expect.poll fails when the polled function does not resolve within the timeout.
- The stale answer
- expect.poll keeps waiting on a function that never resolves.
Answer
**Not forever, as long as you keep a test timeout.** The test will still fail, but `expect.poll`'s own `timeout` probably isn't what stops it.
- **Why the poll timeout may not fire:** I'm going from my memory of Vitest's source and didn't check it against 5.0.3. As I recall, `expect.poll` awaits your callback on every attempt. When its `timeout` (default 1000 ms) runs out, it makes one last attempt and awaits that too. If your callback returns a promise that never settles, the poll may never resolve or reject.
- **What actually stops it:** the test-level timeout (`testTimeout`, default 5000 ms) still applies and fails the test with a timeout error. It only really hangs forever if you set `testTimeout: 0` or pass a timeout of 0 to that test.
- **How to protect yourself:** make the callback itself time-bounded, for example by wrapping the inner call in `Promise.race` with a short timeout or using an `AbortSignal`. Also always `await expect.poll(...)`. An un-awaited poll can let the test finish early or surface failures in the wrong place.Grade
wrong
The judge's reason: It claims expect.poll's own timeout may never fire on a never-settling callback (stale behavior), whereas the key says expect.poll now rejects when the callback doesn't settle within the timeout.
Session log
Agent
**Not forever, as long as you keep a test timeout.** The test will still fail, but `expect.poll`'s own `timeout` probably isn't what stops it. - **Why the poll timeout may not fire:** I'm going from my memory of Vitest's source and didn't check it against 5.0.3. As I recall, `expect.poll` awaits your callback on every attempt. When its `timeout` (default 1000 ms) runs out, it makes one last attempt and awaits that too. If your callback returns a promise that never settles, the poll may never resolve or reject. - **What actually stops it:** the test-level timeout (`testTimeout`, default 5000 ms) still applies and fails the test with a timeout error. It only really hangs forever if you set `testTimeout: 0` or pass a timeout of 0 to that test. - **How to protect yourself:** make the callback itself time-bounded, for example by wrapping the inner call in `Promise.race` with a short timeout or using an `AbortSignal`. Also always `await expect.poll(...)`. An un-awaited poll can let the test finish early or surface failures in the wrong place.