when().thenReturn() always return nil
I'm trying to make getExpositionInfo() to return a value like this
stub(expositionInfoRepository!) { stub in
let expositionInfo = ExpositionInfo(level: .Healthy)
when(stub.getExpositionInfo()).thenReturn(expositionInfo)
}
When the call to the stubbed method is done inside the sut it returns nil
I've been debugging and when setting up the return value:
public extension StubFunctionThenReturnTrait {
@discardableResult
func thenReturn(_ output: OutputType, _ outputs: OutputType...) -> Self {
([output] + outputs).forEach { output in
stub.appendAction(.returnValue(output))
}
return self
}
}
output parameter is always nil, it look like it's overwrited somewhere.
Is there anything wrong with my code?
Regards
Hey @alopezh, could you please include the mocked type? I'll try to reproduce your issue, but if I fail, I will need you to either fork Cuckoo and add the test case that covers this issue or create a minimal project where this issue occurs.
Hi,
Te mocked type is a protocol:
protocol ExpositionInfoRepository {
func getExpositionInfo() -> ExpositionInfo?
func save(expositionInfo: ExpositionInfo)
func clearData()
}
ExpositionInfo is the value that is always nil:
struct ExpositionInfo: Codable, Equatable {
var level: Level
var lastCheck: Date?
var since: Date?
var error: DomainError?
public init(level: Level) {
self.level = level
}
enum Level: String, Codable {
case healthy
case exposed
case infected
}
}
@MatyasKriz any hepl on this?
Thank you