Add assertThatAndStateTurbineConsumed and assertThatAndEffectTurbineConsumed for simpler test setup

This commit is contained in:
Wolf-Martell Montwé 2023-10-20 13:37:44 +02:00
parent f0632d6c9a
commit c29bc90535
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72

View file

@ -72,6 +72,36 @@ fun <T, STATE, EFFECT> assertThatAndMviTurbinesConsumed(
turbines.effectTurbine.ensureAllEventsConsumed()
}
/**
* The `assertThatAndStateTurbineConsumed` function ensures that the assertion passed and
* all events in the state turbine have been consumed.
*/
suspend fun <STATE, EFFECT> MviTurbines<STATE, EFFECT>.assertThatAndStateTurbineConsumed(
assertion: Assert<STATE>.() -> Unit,
) {
assertThat(stateTurbine.awaitItem()).all {
assertion()
}
stateTurbine.ensureAllEventsConsumed()
effectTurbine.ensureAllEventsConsumed()
}
/**
* The `assertThatAndEffectTurbineConsumed` function ensures that the assertion passed and
* all events in the effect turbine have been consumed.
*/
suspend fun <STATE, EFFECT> MviTurbines<STATE, EFFECT>.assertThatAndEffectTurbineConsumed(
assertion: Assert<EFFECT>.() -> Unit,
) {
assertThat(effectTurbine.awaitItem()).all {
assertion()
}
stateTurbine.ensureAllEventsConsumed()
effectTurbine.ensureAllEventsConsumed()
}
/**
* A container class for the state and effect turbines of an MVI ViewModel.
*/