Skip to content

Commit b871725

Browse files
committed
Improve error displayed when the Unconsumed Event cannot be displayed.
1 parent 2625c75 commit b871725

File tree

1 file changed

+17
-3
lines changed
  • tests/testutils/src/main/kotlin/io/element/android/tests/testutils

1 file changed

+17
-3
lines changed

tests/testutils/src/main/kotlin/io/element/android/tests/testutils/PresenterTest.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ import app.cash.molecule.moleculeFlow
1212
import app.cash.turbine.TurbineTestContext
1313
import app.cash.turbine.test
1414
import io.element.android.libraries.architecture.Presenter
15+
import org.junit.Assert.fail
1516
import kotlin.time.Duration
1617

1718
suspend fun <State> Presenter<State>.test(
1819
timeout: Duration? = null,
1920
name: String? = null,
2021
validate: suspend TurbineTestContext<State>.() -> Unit,
2122
) {
22-
moleculeFlow(RecompositionMode.Immediate) {
23-
present()
24-
}.test(timeout, name, validate)
23+
try {
24+
moleculeFlow(RecompositionMode.Immediate) {
25+
present()
26+
}.test(timeout, name, validate)
27+
} catch (t: Throwable) {
28+
if (t::class.simpleName == "KotlinReflectionInternalError") {
29+
// Give a more explicit error to the developer
30+
fail("""
31+
It looks like you have an unconsumed event in your test.
32+
If you get this error, it means that your test is missing to consume one of several events.
33+
You can fix by consuming and check the event with `awaitItem()`, or you can also invoke
34+
`cancelAndIgnoreRemainingEvents()`.
35+
""".trimIndent())
36+
}
37+
throw t
38+
}
2539
}

0 commit comments

Comments
 (0)