---
title: "expectation(that:on:options:willEqual:)"
framework: xctest
role: symbol
role_heading: Instance Method
path: "xctest/xctestcase/expectation(that:on:options:willequal:)"
---

# expectation(that:on:options:willEqual:)

Creates an expectation using key-value observing the test fulfills when the value of an observed property changes to an expected value.

## Declaration

```swift
func expectation<T, V>(that keyPath: KeyPath<T, V>, on observedObject: T, options: NSKeyValueObservingOptions = [.initial, .new, .old], willEqual expectedValue: V) -> XCTKeyPathExpectation<T, V> where T : NSObject, V : Equatable
```

## Parameters

- `keyPath`: The key path for the observed property, relative to the observed object.
- `observedObject`: The object to observe the key path on.
- `options`: A combination of values that specify what to include in observation notifications. For possible values, see doc://com.apple.documentation/documentation/Foundation/NSKeyValueObservingOptions.
- `expectedValue`: A value the property must equal to fulfill the expectation.

## Return Value

Return Value Creates and returns an expectation for the test case.

## See Also

### Creating Asynchronous Test Expectations

- [expectation(description:)](xctest/xctestcase/expectation(description:).md)
- [expectation(for:evaluatedWith:handler:)](xctest/xctestcase/expectation(for:evaluatedwith:handler:).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)
- [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)
