Skip to the editor

Replace the fixed sleep

Waiting & flakiness · level 3 of 5 · PipelineHQ

A sleep is a guess about timing. A retrying assertion waits exactly as long as needed, no more, no less.

The problem

Saving a contact takes about 700ms, so this test sleeps before checking the toast. It works, but it is slow and fragile.

Remove the sleep. Let the assertion wait for the toast instead, it retries until the toast appears.

Refactor without weakening

This test passes but it is written badly. Clean it up, it must stay green and still catch every bug.

Done when

  • Saving a contact still shows the confirmation toast.
  • No fixed sleeps.

Bugs we plant

  • No confirmation toast after saving

We break each one in a copy of the app. Your cleaned-up test has to fail on every copy.

Loading the editor…