Created
January 30, 2019 11:46
-
-
Save charlieInDen/51368b650b49095888b19ddff3a721ff to your computer and use it in GitHub Desktop.
NSNotificationCentre Unit test cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PointsOfInterestTableViewControllerTests: XCTestCase { | |
func testNotification() { | |
let notificationCenter = NotificationCenter() | |
let observer = PointsOfInterestTableViewController(notificationCenter: | |
notificationCenter) | |
XCTAssertFalse(observer.didHandleNotification) | |
// Notification posted to just this center, isolating the test | |
let name = CurrentLocationProvider.authChangedNotification | |
notificationCenter.post(name: name, object: nil) | |
XCTAssertTrue(observer.didHandleNotification) | |
} | |
} | |
PointsOfInterestTableViewControllerTests.defaultTestSuite.run() | |
class CurrentLocationProviderTests: XCTestCase { | |
func testNotifyAuthChanged() { | |
let notificationCenter = NotificationCenter() | |
let poster = CurrentLocationProvider(notificationCenter: notificationCenter) | |
// Notification only sent to this specific center, isolating test | |
let name = CurrentLocationProvider.authChangedNotification | |
let expectation = XCTNSNotificationExpectation(name: name, object: poster, | |
notificationCenter: notificationCenter) | |
poster.notifyAuthChanged() | |
wait(for: [expectation], timeout: 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment