Improve error displayed when the Unconsumed Event cannot be displayed.
This commit is contained in:
parent
4e25a568ac
commit
119053aad1
1 changed files with 17 additions and 3 deletions
|
|
@ -12,6 +12,7 @@ import app.cash.molecule.moleculeFlow
|
||||||
import app.cash.turbine.TurbineTestContext
|
import app.cash.turbine.TurbineTestContext
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
import io.element.android.libraries.architecture.Presenter
|
import io.element.android.libraries.architecture.Presenter
|
||||||
|
import org.junit.Assert.fail
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
|
|
||||||
suspend fun <State> Presenter<State>.test(
|
suspend fun <State> Presenter<State>.test(
|
||||||
|
|
@ -19,7 +20,20 @@ suspend fun <State> Presenter<State>.test(
|
||||||
name: String? = null,
|
name: String? = null,
|
||||||
validate: suspend TurbineTestContext<State>.() -> Unit,
|
validate: suspend TurbineTestContext<State>.() -> Unit,
|
||||||
) {
|
) {
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
try {
|
||||||
present()
|
moleculeFlow(RecompositionMode.Immediate) {
|
||||||
}.test(timeout, name, validate)
|
present()
|
||||||
|
}.test(timeout, name, validate)
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
if (t::class.simpleName == "KotlinReflectionInternalError") {
|
||||||
|
// Give a more explicit error to the developer
|
||||||
|
fail("""
|
||||||
|
It looks like you have an unconsumed event in your test.
|
||||||
|
If you get this error, it means that your test is missing to consume one of several events.
|
||||||
|
You can fix by consuming and check the event with `awaitItem()`, or you can also invoke
|
||||||
|
`cancelAndIgnoreRemainingEvents()`.
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
|
throw t
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue