Cuckoo
Cuckoo copied to clipboard
Cant mock Protocol extensions with default parameters.
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)
}
An interesting observation, thanks for reporting it! We should definitely add this case to the tests and fix it.
I have the same issue.
Any update on this? I'm currently facing the same limitation.