<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTestCase/waitForExpectations(timeout:handler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTestCase(im)waitForExpectationsWithTimeout:handler:"
  },
  "title" : "waitForExpectations(timeout:handler:)"
}
-->

# waitForExpectations(timeout:handler:)

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

```
@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`](/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

This method creates a point of synchronization in the flow of a test. Only one [`waitForExpectations(timeout:handler:)`](/documentation/XCTest/XCTestCase/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 ``doc://com.apple.xctest/documentation/XCTest/XCTestCase``‘s convenience methods only. This method *doesn’t* wait on expectations created manually through initializers on ``doc://com.apple.xctest/documentation/XCTest/XCTestExpectation`` or its subclasses.
> 
> To wait for manually created expectations, use the ``doc://com.apple.xctest/documentation/XCTest/XCTestCase/wait(for:timeout:)`` or ``doc://com.apple.xctest/documentation/XCTest/XCTestCase/wait(for:timeout:enforceOrder:)`` methods, or the corresponding methods on ``doc://com.apple.xctest/documentation/XCTest/XCTWaiter``, passing an explicit list of expectations.

> Note:
> Clients shouldn’t manipulate the run loop while using this API.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)