Contents

waitForExpectations(timeout:handler:)

Waits until the test fulfills all expectations or until it times out.

Declaration

@MainActor func waitForExpectations(timeout: TimeInterval, handler: (@Sendable ((any Error)?) -> Void)? = nil)

Parameters

  • timeout:

    The time, in seconds, the test allows for the fulfillment of the expectations. The default timeout allows the test to run until it reaches its execution time allowance.

  • handler:

    An optional Xcwaitcompletionhandler block to invoke after a test fulfills all expectations or the wait time elapses. A test treats a timeout as a failure.

Discussion

This method creates a point of synchronization in the flow of a test. Only one waitForExpectations(timeout:handler:) can be active at any given time, but you can chain together multiple discrete sequences of “create expectations and wait for them to be fulfilled”.

See Also

Waiting for Expectations