expectation(for:evaluatedWith:handler:)
Creates an expectation that the test fulfills by evaluating the predicate with the specified object.
Declaration
func expectation(for predicate: NSPredicate, evaluatedWith object: Any?, handler: XCTNSPredicateExpectation.Handler? = nil) -> XCTestExpectationParameters
- predicate:
The predicate to evaluate.
- object:
The object XCTest evaluates the predicate against.
- handler:
An optional handler that performs custom evaluation when
predicateevaluates as True.
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.
See Also
Creating Asynchronous Test Expectations
expectation(description:)expectation(forNotification:object:handler:)expectation(forNotification:object:notificationCenter:handler:)keyValueObservingExpectation(for:keyPath:expectedValue:)expectation(that:on:options:willEqual:)keyValueObservingExpectation(for:keyPath:handler:)expectation(that:on:options:willSatisfy:)expectation(that:on:options:willSatisfy:)expectation(that:on:options:willSatisfy:)