Skip to content

[SR-907] Add convenience XCTestExpectation constructors for NSNotification #402

Closed
@modocache

Description

@modocache
mannequin
Previous ID SR-907
Radar None
Original Reporter @modocache
Type Improvement
Status Closed
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s XCTest
Labels Improvement, StarterBug
Assignee apps.yoon (JIRA)
Priority Medium

md5: 2bc0310ca30f22236b57ae9be6504fd5

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). Add the following convenience constructors:

1. expectationForNotification:object:handler:
2. expectationForPredicate:evaluatedWithObject:handler:

Also, note that you'll need to add the following closure typealiases as well:

typedef BOOL (^XCNotificationExpectationHandler)(NSNotification *notification);
typedef BOOL (^XCPredicateExpectationHandler)();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions