diff --git a/tests/testutils/src/main/kotlin/io/element/android/tests/testutils/PresenterTest.kt b/tests/testutils/src/main/kotlin/io/element/android/tests/testutils/PresenterTest.kt index c5acc9d510..2967e4bb67 100644 --- a/tests/testutils/src/main/kotlin/io/element/android/tests/testutils/PresenterTest.kt +++ b/tests/testutils/src/main/kotlin/io/element/android/tests/testutils/PresenterTest.kt @@ -12,6 +12,7 @@ import app.cash.molecule.moleculeFlow import app.cash.turbine.TurbineTestContext import app.cash.turbine.test import io.element.android.libraries.architecture.Presenter +import org.junit.Assert.fail import kotlin.time.Duration suspend fun Presenter.test( @@ -19,7 +20,20 @@ suspend fun Presenter.test( name: String? = null, validate: suspend TurbineTestContext.() -> Unit, ) { - moleculeFlow(RecompositionMode.Immediate) { - present() - }.test(timeout, name, validate) + try { + moleculeFlow(RecompositionMode.Immediate) { + 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 + } }