Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant mock Protocol extensions with default parameters. #408

Open
RoryKelly opened this issue Dec 23, 2021 · 3 comments
Open

Cant mock Protocol extensions with default parameters. #408

RoryKelly opened this issue Dec 23, 2021 · 3 comments
Labels

Comments

@RoryKelly
Copy link

RoryKelly commented Dec 23, 2021

We have an autogenerated Network Stack. Cuckoo cannot mock protocol extensions that have functions with default parameters.

protocol ApolloNetworkService {
    var apolloClient: ApolloClient { get }

    func allClashesFeedQueryWatch(cachePolicy: CachePolicy) -> AnyPublisher<AllClashesFeedQueryModel, Error>

}

extension ApolloNetworkService {
    func allClashesFeedQueryWatch( cachePolicy: CachePolicy = .returnCacheDataAndFetch ) -> AnyPublisher<AllClashesFeedQueryModel, Error> {
       // this function cannot be mocked. 
    }
}


func test() {
     let mockNetwork = MockApolloNetworkService()

     stub(networkService) { stub in
                    when(allClashesFeedQueryWatch(cachePolicy: any())).thenReturn(Empty().eraseToAnyPublisher())
      }
  
   //  This calls actual implementation 
   mockNetwork. allClashesFeedQueryWatch() 

   // this returns mock
   mockNetwork. allClashesFeedQueryWatch(cachePolicy: .fromCache) 
}
@MatyasKriz MatyasKriz added the bug label Jan 24, 2022
@MatyasKriz
Copy link
Collaborator

An interesting observation, thanks for reporting it! We should definitely add this case to the tests and fix it.

@ppamorim

This comment was marked as duplicate.

@stonko1994
Copy link
Contributor

Any update on this? I'm currently facing the same limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants