'Swift ios unit test mock API

I would like to have this API provider unit test. but i fail to cover this kind of API.

I have tried, the mock function is called, but it does not count the unit test coverage which line is still not passing (in red color)

class APIProviderTest {
  func test_API {
     sut = MockAPIProvider()
     let promise = sut.sendEmailVerificationApi(userEmail: "12312")
        XCTAssertAfterPromiseSuccess(promise: promise, assertActions: {
            response in
            XCTAssertTrue(response)
        })
   }
}
class MockAPIProvider: APIProvider {
 var isFuncCalled = false
 func sendEmailCodeApi(userEmail: String) -> Promise<Bool> {
    isFuncCalled = true
 }
}

Class APIProvider {
   func sendEmailCodeApi(userEmail: String) -> Promise<Bool> {
       return getToken.execute()
           .compactMap { $0.accessToken }
           .then { [self]
               accessToken -> Promise<Bool> in
               return sendEmailVerificationCode.execute(
                   token: accessToken,
                   userEmail: userEmail
               ).then {
                   res -> Promise<Bool> in
                   res == "success" ? .value(true) : .value(false)
               }
           }
           .recover { _ -> Promise<Bool> in
               return .value(false)
           }
   }
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source