Hi guys :slightly_smiling_face: Is there anyway to...
# mockk
j
Hi guys 🙂 Is there anyway to make the second mock declaration work?
Copy code
class DummyUseCase {

    operator fun invoke(): String = TODO()
}

@Test
fun test() {
    val dummyUseCase1: DummyUseCase = mockk()
    every { dummyUseCase1.invoke() } returns ""
    val dummyUseCase2: DummyUseCase = mockk {
        every { this.invoke() } returns ""
    }
}
In the second case, I have a compilation error: “Not enough information to infer type variable T” (I’m fine with the first declaration but we’ve been trying this
operator invoke
thing for our use cases that was showcased in one of the recent MAD Skills video and we use sometimes the second mock declaration) Thanks! 🙂
s
If this is the same issue I've run into in the past, the workaround is
Copy code
every { this@mockk.invoke() } returns ""
e
exactly, wrong
this
if you simply wrote
every { invoke() }
that should work too
j
Yes! Now it works 🙏 🙏
unfortunately, simple invoke does not, it’s the first thing I tried
e
hmm that's odd, I didn't think there was another no-arg invoke overload in that scope
j
yeah, that’s what was confusing me:
I'm not really sure what it's supposed to be for 🤔
e
if you put a newline after
every
you'll see another receiver there