Try running assertions a few times, until they pass (or run out of time):

eventually(options, function)

options:

timeout: milliseconds to wait before giving up (default: 1000)

frequency: milliseconds to wait between attempts (default: 50)

function: code to execute on each attempt

To assert that a background process will have some effect in a non-deterministic (but relatively short) time, you can group your assertions in an eventually block. If an exception is thrown the first time -- for example, by a failing assertion -- it will delay for a small period of time, then try again, repeating until the code executes without exception or the time runs out.