https://kotlinlang.org logo
#orbit-mvi
Title
# orbit-mvi
j

Jon Bailey

11/01/2023, 5:51 PM
Seperately, for the old testing framework in my actual tests if I replace runTest with this function (in the thread along with a sample test), then the test works but I don't know why that would be needed now?
Copy code
fun runTestWithForceExit(
    context: CoroutineContext = EmptyCoroutineContext,
    dispatchTimeoutMs: Long = 10_000,
    testBody: suspend TestScope.() -> Unit,
) {
    var finished = false
    runCatching {
        runTest(context, dispatchTimeoutMs) {
            withTimeout(dispatchTimeoutMs) {
                testBody()
            }
            finished = true
            runCatching { cancel() }
        }

    }.exceptionOrNull()?.let {
        if (!finished || it !is CancellationException) {
            throw it
        }
    }
}
Eg a test:
Copy code
@Test
    fun exampleTest() = runTestWithForceExit { //runTest gets the "After waiting for 10s..." error since 6.1.0
        val host = ExampleContainerHost(this).test()

        host.testIntent {
            doSomethingUseful()
        }
        host.lastState() assertEquals ExampleState("foo")
    }