---
title: "waitForExpectations(timeout:handler:)"
framework: xctest
role: symbol
role_heading: Instance Method
path: "xctest/xctestcase/waitforexpectations(timeout:handler:)"
---

# waitForExpectations(timeout:handler:)

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

## Declaration

```swift
@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 doc://com.apple.xctest/documentation/XCTest/XCWaitCompletionHandler block to invoke after a test fulfills all expectations or the wait time elapses. A test treats a timeout as a failure.

## Discussion

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”. important: This method waits on expectations created with XCTestCase‘s convenience methods only. This method doesn’t wait on expectations created manually through initializers on XCTestExpectation or its subclasses. To wait for manually created expectations, use the wait(for:timeout:) or wait(for:timeout:enforceOrder:) methods, or the corresponding methods on XCTWaiter, passing an explicit list of expectations. note: Clients shouldn’t manipulate the run loop while using this API.

## See Also

### Waiting for Expectations

- [fulfillment(of:timeout:enforceOrder:)](xctest/xctestcase/fulfillment(of:timeout:enforceorder:).md)
- [wait(for:)](xctest/xctestcase/wait(for:).md)
- [wait(for:enforceOrder:)](xctest/xctestcase/wait(for:enforceorder:).md)
- [wait(for:timeout:)](xctest/xctestcase/wait(for:timeout:).md)
- [wait(for:timeout:enforceOrder:)](xctest/xctestcase/wait(for:timeout:enforceorder:).md)
- [XCWaitCompletionHandler](xctest/xcwaitcompletionhandler.md)
- [XCTestError](xctest/xctesterror.md)
- [XCTestError.Code](xctest/xctesterror/code.md)
- [XCTestErrorDomain](xctest/xctesterrordomain.md)
