Skip to content

Instantly share code, notes, and snippets.

@charlieInDen
Created January 30, 2019 11:46
Show Gist options
  • Save charlieInDen/51368b650b49095888b19ddff3a721ff to your computer and use it in GitHub Desktop.
Save charlieInDen/51368b650b49095888b19ddff3a721ff to your computer and use it in GitHub Desktop.
NSNotificationCentre Unit test cases
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