sabirvirtuoso / Mockit

A simple mocking framework for Swift, inspired by the famous http://mockito.org/
MIT License
120 stars 27 forks source link

Async #4

Closed hugobast closed 7 years ago

hugobast commented 7 years ago

I'm curious to know what approach you recommend when trying to verify mocks in an async setup. I'm using Quick/Nimble if that matters.

sabirvirtuoso commented 7 years ago

Use something like this

_ = yourServiceMock.when().call(withReturnValue: yourServiceMock.login("dummyLoginName", password: "dummyPassword", webServiceResponse: YourWebServiceResponseStub()),
                andArgumentMatching: [Anything(), Anything(), Anything()]).thenDo {
            (args: [Any?]) -> Void in

            (args[2] as! YourWebServiceResponseHandler).success(200, responseObject: loginObjectToBeReturnedOnAPICall)

// or may be for failure you can use 
// _ = (args[2] as! `YourWebServiceResponseHandler).failure(401,` error: errorDetails)
        }