How to write unit test to get nsnotification asynchrony?

I call the web rest service with a completion handler, and if that succeeds, I will send NSNotification.

The problem is how to write unit test to claim that a notification was sent if successful.

Any help would be appreciated.

+4
source share
1 answer

You can add the expected 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 separate these two tests. One for fetching data (checked with a stub) and one for sending notifications.

+6
source

Source: https://habr.com/ru/post/1620875/


All Articles