In what situation would one use expectationForNotification in swift testing -
i'm little confused what/when expectationfornotification opposed expectationwithdescription. i've been unable find clear examples in swift when , call.
i'm assuming perhaps test notifications looks might more convenient wrapper around whole addobserver()
call of notification center.
could give brief explanation of does, when use it, , perhaps few lines of sample code?
thanks
as have imagined expectationfornotification convenience expectation checking if notification raised.
this test:
func testitshouldraiseapassnotificationv1() { let expectation = expectationwithdescription("notification raised") let sub = nsnotificationcenter.defaultcenter().addobserverforname("evpassed", object: nil, queue: nil) { (not) -> void in expectation.fulfill() } nsnotificationcenter.defaultcenter().postnotificationname("evpassed", object: nil) waitforexpectationswithtimeout(0.1, handler: nil) nsnotificationcenter.defaultcenter().removeobserver(sub) }
can replaced one:
func testitshouldraiseapassnotificationv2() { expectationfornotification("evpassed", object: nil, handler: nil) nsnotificationcenter.defaultcenter().postnotificationname("evpassed", object: nil) waitforexpectationswithtimeout(0.1, handler: nil) }
you can find explanation in objc.io number.
Comments
Post a Comment