Hello! <https://stackoverflow.com/questions/744005...
# mockk
e
Why mock the function type instead of just sending the function which returns your mocked result?
d
What do you mean by sending the function? Something like ``PricedStockListLoader(stock, { _ -> Price(666) })` ?
e
yes
d
I was trying to be consistent between the collaborators, and to show that you could mockk functions, only to find that I can’t!
e
Gotcha.. this works for me:
Copy code
test("mock function type") {
   val mockedFunction = mockk<(Int) -> String>()
   every { mockedFunction.invoke(5) } returns "hello"
   mockedFunction(5) shouldBe "hello"
}
(Using Kotest, not sure if JUnit is messing with anything)
Using MockK 1.13.2
d
Hmm, then I wonder if JUnit is messing with something.
Or rather, kotest is compensating for something
My gut says coroutines are marching in the direction of this problem
e
Not sure where coroutines might mess with things. No suspending functions in sight afaik?
d
I was thinking that kotest is coroutine aware and JUnit isn’t…
e
It is 🙂
d
but this is fine:
Copy code
class Delme {
    @Test
    fun test() {
        val mockedFunction = mockk<(Int) -> String>()
        every { mockedFunction.invoke(5) } returns "hello"
        assertEquals("hello", mockedFunction(5))
    }
}
e
what is
anItem
in your case?
d
its a plain old data class
I really appreciate the help, but have to do an urgent thing. Will report back on investigations.
e
No worries, and appreciate if you get back with the results 🙂
If you push
PricedStockListLoaderTest
to Github I can take another look at it 🙂
d
Some awesome detective work on SO by someone (@irus?) https://stackoverflow.com/a/74414374/97777