<!--
{
  "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:willSatisfy:)-85or0",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "s:So10XCTestCaseC0A0E11expectation4that2on7options11willSatisfyAC21XCTKeyPathExpectationCyxq_Gs03KeyJ0Cyxq_G_xSo26NSKeyValueObservingOptionsVSbx_10Foundation0mN14ObservedChangeVyq_GtYbcSgtSo8NSObjectCRbzr0_lF"
  },
  "title" : "expectation(that:on:options:willSatisfy:)"
}
-->

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

Creates an expectation using key-value observing to monitor changes to a given key path on a given object.

```
func expectation<T, V>(that keyPath: KeyPath<T, V>, on observedObject: T, options: NSKeyValueObservingOptions = [.initial, .new, .old], willSatisfy filter: XCTKeyPathExpectation<T, V>.SynchronousFilter? = nil) -> XCTKeyPathExpectation<T, V> where T : NSObject
```

## Parameters

`keyPath`

The key path to observe.

`observedObject`

The object to observe the key path on.

`options`

Options to pass to Foundation when observing changes.

`filter`

A syncronous predicate function you use to test observed changes to a key path. If `nil`, the first observed change fulfills the expectation.

## Return Value

Creates and returns an expectation associated with the test case that a specific key-value observing (KVO) condition fulfills, see <doc://com.apple.documentation/documentation/Swift/using-key-value-observing-in-swift>.

---

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)