Statement
End-to-end tests that wait with sleep(2000) are slow and flaky. Write waitFor(condition, { timeout, interval }): call condition() (it may be async) until it returns a truthy value and resolve with that value. If condition throws, it counts as “not yet” and you keep trying. Wait interval ms between attempts, but never past the timeout. When time runs out, reject with an Error whose message is Timed out after <timeout>ms and, if the last attempt threw, append : <that error's message>.