Instance Method

waitForExpectations(timeout:handler:)

Waits until all expectations are fulfilled or the timeout is reached.

Declaration

func waitForExpectations(timeout: TimeInterval, handler: XCWaitCompletionHandler? = nil)

Parameters

timeout

The amount of time within which all expectations must be fulfilled.

handler

An optional XCWaitCompletionHandler block to invoke when all expectations have been fulfilled or when the wait timeout is triggered. (Timeout is always treated as a test 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 multiple discrete sequences of “create expectations and wait for them to be fulfilled” can be chained together.

See Also

Waiting for Expectations

func wait(for: [XCTestExpectation], timeout: TimeInterval)

Waits on a group of expectations for up to the specified timeout.

func wait(for: [XCTestExpectation], timeout: TimeInterval, enforceOrder: Bool)

Waits on an array of expectations and specifies whether they must be fulfilled in the given order.

typealias XCWaitCompletionHandler

A block to be called when a call to waitForExpectations(timeout:handler:) has all of its expectations fulfilled, or times out.