How can I invoke lambdas in Unit Tests with MockK?...
# announcements
How can I invoke lambdas in Unit Tests with MockK? I'm listening to changes of my view in the presenter's function onViewAttached(view), e.g. onLoginListener:
Copy code
view.onLoginListener = {
    launch {
        val user = view.userTextField.getTextProperty()
        val pass = view.passTextField.getTextProperty()

        val result = doLogin(user, pass)
        // ...
It works perfectly fine on Android and iOS devices, but I can't get tests running. If I invoke view.onLoginListener in the test function, nothing happens. The presenter doesn't run the code block. Here is an excerpt of my test class: (see reply in thread)
Copy code
class LoginPresenterTest {
    private lateinit var presenter: LoginPresenter

    lateinit var view: LoginView

    private val user = "MyUser"
    private val pass = "MyPass"

    lateinit var doLogin: DoLogin

    fun onSetup(): Unit = MockKAnnotations.init(this).also {

        presenter = LoginPresenter(doLogin)

        coEvery { doLogin("MyUser", "MyPass") } returns LoginResult.Success

        every { view.onLoginListener = any() } just Runs
        every { view.onLoginListener } returns {}
        every { view.userTextField.getTextProperty() } returns user
        every { view.passTextField.getTextProperty() } returns pass

    fun onLoginSuccess() {
        runBlocking { presenter.attachView(view) }


        coVerify {

            doLogin(user, pass)