Description
Previous ID | SR-1110 |
Radar | None |
Original Reporter | @modocache |
Type | New Feature |
Status | Closed |
Resolution | Done |
Attachment: Download
Additional Detail from JIRA
Votes | 0 |
Component/s | XCTest |
Labels | New Feature, StarterBug |
Assignee | apps.yoon (JIRA) |
Priority | Medium |
md5: 80de972c44d4ad944e39eb5cd68136b2
Issue Description:
Apple XCTest offers several convenient methods for constructing XCTestExpectations:
@interface XCTestCase : XCTest
// ...
- (XCTestExpectation *)keyValueObservingExpectationForObject:(id)objectToObserve keyPath:(NSString *)keyPath expectedValue:(nullable id)expectedValue;
- (XCTestExpectation *)keyValueObservingExpectationForObject:(id)objectToObserve keyPath:(NSString *)keyPath handler:(nullable XCKeyValueObservingExpectationHandler)handler;
- (XCTestExpectation *)expectationForNotification:(NSString *)notificationName object:(nullable id)objectToObserve handler:(nullable XCNotificationExpectationHandler)handler;
- (XCTestExpectation *)expectationForPredicate:(NSPredicate *)predicate evaluatedWithObject:(id)object handler:(nullable XCPredicateExpectationHandler)handler;
// ...
@end
Key-value observing doesn't exist in native Swift, but NSNotification and NSPredicate do (thanks to swift-corelibs-foundation). swift-corelibs-xctest already defines a constructor for NSNotification: https://github.com/yoonapps/swift-corelibs-xctest/blob/c2a9258c7c17e32bf9082709ef111e59aba86a95/Sources/XCTest/XCTestCase.swift#L324. This was added in #85
Add the constructor for NSPredicate: -[XCTestCase expectationForPredicate:evaluatedWithObject:handler:]
.
Also, note that you'll need to add the following closure typealias as well: typedef BOOL (^XCPredicateExpectationHandler)();
.
https://bugs.swift.org/browse/SR-907 is a great reference on how to approach this task.