How can Alamofire calls such as request, download, upload be mocked so that one has control over the response and the flow in the callback?
I would like to test the response closures that Alamofire calls, without hitting the network. I would also like this to be self contained, without doing response rewrites with Charles.
It doesnt seem to be possible to mock certain Alamofire objects directly due to the internals and private methods etc.
Has anyone successfully managed to test these Alamofire response handlers?
E.g.
Alamofire.request("https://httpbin.org/get").responseJSON { response in
// using the mocked response here to control
// and assert execution flow inside this callback
}
Or
public func should(_ manager: SessionManager,
retry request: Request,
with error: Error,
completion: @escaping RequestRetryCompletion) {
// using the mocked request.task?.response here to control
// and assert execution flow inside this callback
}
I also cant seem to initialize any type of Alamofire Request (e.g. DataRequest) as compiler complains with DataRequest() and there are no initializers in the class.
Aucun commentaire:
Enregistrer un commentaire