Replace Fixed Test Delays with Vitest expect.poll
Fixed-delay sleeps make async tests either flaky or slow. Vitest's expect.poll retries standard matchers until a condition passes, giving you a deterministic middle ground—if you tune it correctly.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Fixed-delay sleeps make async tests either flaky or slow. Vitest's expect.poll retries standard matchers until a condition passes, giving you a deterministic middle ground—if you tune it correctly.
Mocha detects async test completion via returned promises, async functions, or the done callback. This guide shows correct patterns, common pitfalls (missing returns, mixed mechanisms, timeout misconfig), and verification steps to ensure reliable async tests.
An architecture note on Mocha's two async completion mechanisms — the done callback and returned Promises — covering when each fits, timeout configuration, and the failure modes that should change your design.
Stop slowing down your CI pipeline with real-time delays. Learn how to use jest.useFakeTimers(), advanceTimersByTime, and runAllTimers to test asynchronous JavaScript without waiting for real delays.
Context I'm designing a test suite that relies on Bun's built-in test runner, using its Jest-style glob discovery for .test.ts files alongside source code. Some tests intentionally exercise asynchronous code paths where promises may reject outside an explicit await or try/catch . Uncertainty The documented behavior for unhandled promise rejections inside tes