Instance Method

expectation(forNotification:object:handler:)

Creates an expectation that is fulfilled when a specific NSNotification is received for a given object.

Declaration

func expectation(forNotification notificationName: NSNotification.Name, object objectToObserve: Any?, handler: XCTNSNotificationExpectation.Handler? = nil) -> XCTestExpectation

Parameters

notificationName

The notification to register for.

objectToObserve

The object to observe.

handler

An optional XCTNSNotificationExpectation.Handler block. If not provided, the expectation will be fulfilled by the first notification matching the specified name from the observed object.

Discussion

See Also

Creating Asynchronous Test Expectations

func expectation(description: String) -> XCTestExpectation

Creates a new expectation with an associated description.

func expectation(for: NSPredicate, evaluatedWith: Any?, handler: XCTNSPredicateExpectation.Handler?) -> XCTestExpectation

Creates an expectation that is fulfilled if the predicate returns true when evaluated with the given object.

func keyValueObservingExpectation(for: Any, keyPath: String, expectedValue: Any?) -> XCTestExpectation

Creates an expectation that uses Key Value Observing to observe a value until it matches an expected value.

func keyValueObservingExpectation(for: Any, keyPath: String, handler: XCTKVOExpectation.Handler?) -> XCTestExpectation

Creates an expectation that uses Key Value Observing to observe a value and respond to changes in that value by calling a provided handler.