所以我需要測試NSNotification
是否已發佈。我嘗試了下面的代碼來窺探論證。在獼猴桃中測試NSNotification iOS
[[NSNotificationCenter defaultCenter] stub:@selector(postNotification:)];
__block KWCaptureSpy *notificationSpy = [[NSNotificationCenter
defaultCenter] captureArgument:@selector(postNotification:) atIndex:0];
[[theValue(notificationSpy.argument.name) should] equal:theValue(SOME_NOTIFICATION)];
但這個問題是因爲它是異步的參數並不總是在測試前捕獲。我無法爲notificationSpy.argument.name添加shouldEventually
,因爲它在捕獲前會拋出NSInternalConsistencyException
以訪問參數。
我也試過, [[SOME_NOTIFICATION should] bePosted];
它也失敗了。
即使我使用expectFutureValue,我仍然會得到NSInternalConsistencyException,就像您提到的那樣。 – Vig
另外,只是想知道你將如何監視多個通知?即說我已經發布了兩個不同的通知notificationSpy.argument.name只是第一個權利,我將如何窺探第二個? – Vig
嗯......我發佈之前測試了代碼,它對我很有用。你在用什麼SDK? – Cristik