Jon Bailey
11/01/2023, 5:51 PMfun 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
}
}
}
@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")
}