2026-09-14 · 6 min
The event loop, in the language of flakes
Synchronous code runs first. Then microtasks (promise then/catch, queueMicrotask). Then timers and I/O. If a then queues another then, those still run before setTimeout(fn, 0).
That is why a test that asserts immediately after firing a click can pass locally and fail in CI: the handler scheduled work. Prefer locators that wait over sleep. When you must reason about order, draw the two queues on paper.
Workers exist for CPU. Network does not block the thread if you use async APIs. A 5-second loop in a click handler will freeze the page — and your test — until it finishes.