単体テストしたいメソッドがあります:
- (void)fetchInfo {
[AMKAccountService getInfo]
.then(^(AMKInfoResponse *response) {
if (response.accounts.count > 0) {
_viewModel = [[AMKInfoViewModel alloc] initWithInfoResponse:response];
[self.view setAsOfDate:_viewModel.asOfDate];
} else {
[self.view showError:[AMKStrings feedbackForCode:@"testError"]];
}
}).catch(^(NSError *error) {
DLog(@"Error getting info: %@", error);
[self.view showError:[AMKStrings feedbackForCode:@"testError"]];
});
}
このメソッドでは、「getInfo」メソッドがサービス呼び出しを行い、タイプ PMKPromise オブジェクトの応答を返します。
私の質問は、getInfo メソッドをモックし、1 つの単体テストに対して呼び出される「then」ブロックと、他の単体テストに対して呼び出される「catch」ブロックを作成する方法です。
[更新] getInfo メソッドは次のとおりです。
+ (PMKPromise *)getInfo {
AMKServicesClient *client = [AMKServicesClient sharedInstance];
return [client GET:@"/amk-web-services/rest/info" parameters:nil].thenInBackground(^(NSDictionary *responseDictionary) {
return [[AMKInfoResponse alloc] initWithResponse:responseDictionary];
});
}