Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How write unit test for receiving nsnotification asynchronous?

I call rest web servic with completion handler and if succeed I send NSNotification.

The problem is how to write unit test to assert that the notification is sent in case of success.

Any help will be appreciated.

like image 745
Abdelrahman Avatar asked Dec 19 '15 13:12

Abdelrahman


1 Answers

You can add an expectation for the notification:

expectationForNotification("BlaBlaNotification", object: nil) { (notification) -> Bool in

// call the method that fetches the data
sut.fetchData()  

waitForExpectationsWithTimeout(5, handler: nil)

But personally I would split this is two tests. One for the fetching of the data (tested using a stub) and one for the sending of the notification.

like image 50
dasdom Avatar answered Sep 19 '22 06:09

dasdom