---
title: "expectation(for:evaluatedWith:handler:)"
framework: xctest
role: symbol
role_heading: Instance Method
path: "xctest/xctestcase/expectation(for:evaluatedwith:handler:)"
---

# expectation(for:evaluatedWith:handler:)

Creates an expectation that the test fulfills by evaluating the predicate with the specified object.

## Declaration

```swift
func expectation(for predicate: NSPredicate, evaluatedWith object: Any?, handler: XCTNSPredicateExpectation.Handler? = nil) -> XCTestExpectation
```

## Parameters

- `predicate`: The predicate to evaluate.
- `object`: The object XCTest evaluates the predicate against.
- `handler`: An optional handler that performs custom evaluation when predicate evaluates as doc://com.apple.documentation/documentation/Swift/true.

## Discussion

Discussion The expectation periodically evaluates the predicate and also may use notifications or other events to optimistically re-evaluate. The test fulfills the expectation when the predicate evaluates to true. When you use the resulting expectation from Swift and await using fulfillment(of:timeout:enforceOrder:) rather than wait(for:), XCTest evaluates predicate on the main actor. If a handler isn’t provided, the first successful evaluation of the predicate fulfills the expectation. If you provide a handler, the handler can override this default behavior to tailor the conditions that fulfill the expectation. note: For more control over predicate-based expectations, use XCTNSPredicateExpectation instead of this convenience method.

## See Also

### Creating Asynchronous Test Expectations

- [expectation(description:)](xctest/xctestcase/expectation(description:).md)
- [expectation(forNotification:object:handler:)](xctest/xctestcase/expectation(fornotification:object:handler:).md)
- [expectation(forNotification:object:notificationCenter:handler:)](xctest/xctestcase/expectation(fornotification:object:notificationcenter:handler:).md)
- [keyValueObservingExpectation(for:keyPath:expectedValue:)](xctest/xctestcase/keyvalueobservingexpectation(for:keypath:expectedvalue:).md)
- [expectation(that:on:options:willEqual:)](xctest/xctestcase/expectation(that:on:options:willequal:).md)
- [keyValueObservingExpectation(for:keyPath:handler:)](xctest/xctestcase/keyvalueobservingexpectation(for:keypath:handler:).md)
- [expectation(that:on:options:willSatisfy:)](xctest/xctestcase/expectation(that:on:options:willsatisfy:)-6itb.md)
- [expectation(that:on:options:willSatisfy:)](xctest/xctestcase/expectation(that:on:options:willsatisfy:)-292oj.md)
- [expectation(that:on:options:willSatisfy:)](xctest/xctestcase/expectation(that:on:options:willsatisfy:)-85or0.md)
