Hi - and another mockk question. Given the followi...
# mockk
m
Hi - and another mockk question. Given the following properties of a class:
Copy code
val scanObservers = mutableListOf<(Scan) -> Unit>()
var scan: Scan by Delegates.observable(
        Scan(
            "",
            "",
            ""
        )
    ) { _, _, new -> scanObservers.forEach { it(new) } }
How can I add a mocked lambda in my unit test with mockk? Some sort of:
Copy code
@Test
fun verifyObserver() {
  // Arrange
  val scan = Scan("foo", "bar", "baz")
  val myMockedLambda = whatShouldIPutInHere???
  myObj.scanObservers.add(myMockedLambda)

  // Act
  myObj.scan = scan
  
  // Assert
  verify(exactly = 1) { myMockedLambda(scan) }
}
m
Copy code
val myMockedLambda = mockk<(Scan) -> Unit>()
if you don't want to repeat the lambda type over, declare a type alias
Copy code
typealias ScanFn = (Scan) -> Unit
val myMockedLambda = mockk<ScanFn>()
m
many thanks 🙂