Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
No se puede llamar al valor del tipo que no es función, marco de simulación rápido + cuco

Estoy tratando de burlarme de un servicio con cuckoo en swift. Aquí está la función original en el servicio:

 typealias GetAppConfigCompletionHandler = (_ response: AppConfig) -> Void func getAppConfig(delegate: ErrorCoordinatorDelegate, retryClosure: (() -> Void)?, response responseCallback: @escaping GetAppConfigCompletionHandler) { guard let appConfigUrl = "some/url" HttpClientService<AppConfig>.makeRequest(errorCoordinatorDelegate: delegate, retryClosure: retryClosure, url: appConfigUrl) { appConfig in responseCallback(appConfig) } }

Luego, en las pruebas, intento simular EndPointService para que devuelva la llamada a mi valor simulado en lugar de llamar a una API:

 guard let mockedAppConfig: AppConfig = JsonTestingHelper.decodeJSON(resourceName: "mockAppConfig", model: AppConfig.self) else { fail("failed to create mockAppConfig from JSON") return } stub(endPointServiceMock) { mock in when(mock.getAppConfig(delegate: any(), retryClosure: any(), response: any())).then { callback in callback(mockedAppConfig) //error is here } }

Y así es como se ve la función simulada generada:

 func getAppConfig(delegate: ErrorCoordinatorDelegate, retryClosure: (() -> Void)?, response responseCallback: @escaping GetAppConfigCompletionHandler) { return cuckoo_manager.call("getAppConfig(delegate: ErrorCoordinatorDelegate, retryClosure: (() -> Void)?, response: @escaping GetAppConfigCompletionHandler)", parameters: (delegate, retryClosure, responseCallback), escapingParameters: (delegate, retryClosure, responseCallback), superclassCall: Cuckoo.MockManager.crashOnProtocolSuperclassCall() , defaultCall: __defaultImplStub!.getAppConfig(delegate: delegate, retryClosure: retryClosure, response: responseCallback)) }

Por lo que parece, debería funcionar, sin embargo, el compilador se queja en la línea de devolución de llamada (mockedAppConfig):

No se puede llamar al valor del tipo que no es de función '(ErrorCoordinatorDelegate, (() -> Void)?, MockEndPointServiceType.GetAppConfigCompletionHandler)' (también conocido como '(ErrorCoordinatorDelegate, Optional<(() -> ())>, (AppConfig) -> ( ))')

¿Qué me estoy perdiendo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El mensaje de error, aunque un poco complejo, le dice exactamente cuál es el problema;

Cuando llama a callback(mockedAppConfig) , su variable de callback de llamada es en realidad una tupla con 3 parámetros (un ErrorCoordinatorDelegate , una función Void opcional y una función que toma un parámetro AppConfig ).

Para corregir este error, todo lo que necesita hacer es:

 callback.2(mockedAppConfig)

(Así es como hace referencia a cualquier parámetro sin nombre de una tupla)

O, mejor aún, podrías hacer que tu stub se vea así:

 stub(endPointServiceMock) { mock in when(mock.getAppConfig(delegate: any(), retryClosure: any(), response: any())).then { _, _, callback in callback(mockedAppConfig) } }

Que es un poco más estándar y menos oscuro :)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!