<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "tvOS: 13.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTestCase/expectation(that:on:options:willEqual:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "s:So10XCTestCaseC0A0E11expectation4that2on7options9willEqualAC21XCTKeyPathExpectationCyxq_Gs03KeyJ0Cyxq_G_xSo26NSKeyValueObservingOptionsVq_tSo8NSObjectCRbzSQR_r0_lF"
  },
  "title" : "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.

```
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

Creates and returns an expectation for the test case.

---

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)