Skip to content

MockMode.autoUnit does not work when mocking functional types #19

@marchuk0

Description

@marchuk0

AutoUnit does not work for functional types.

The first test from the example below will fail, while the second one is successful.

Kotlin multiplatform version: 1.9.24
Kotlin multiplatform target: js
Mokkery version: 1.9.24-1.7.0

interface TestInterface {
    fun invokeInterface(foo: Int)
}

class Example {

    @Test
    fun testAutoUnitDoesNotWorkForFunction() {
        val functionMock = mock<(foo: Int) -> Unit>(MockMode.autoUnit)
        functionMock.invoke(1) // Fails with CallNotMockedException: Call Function1(1).invoke(p1 = 1) not mocked!
    }

    @Test
    fun testAutoUnitWorkForInterface() {
        val functionMock = mock<TestInterface>(MockMode.autoUnit)
        functionMock.invokeInterface(1) // success
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions