https://kotlinlang.org logo
#mockk
Title
# mockk
e

Emil Kantis

06/10/2021, 7:28 PM
Setting up a mock like this causes problems because the x in every will not refer to the x on the mocked
Point
Copy code
data class Point(val x: Int, val y: Int) 

val x = 7
val mockPoint = mockk<Point> { 
  every { x } returns x
}
If the receiver in the
every
block would be <T> (or Point in this case), I believe x would bind correctly, but perhaps that causes other issues?
k

knthmn

06/11/2021, 1:20 AM
You can use labels
Copy code
val mockPoint = mockk<Point> {
    every { this@mockk.x } returns x
}
☝️ 1
🙏 1
5 Views