Pablo
12/15/2021, 3:23 PMinternal class MyPresenter @Inject constructor(...) {
private val _uiState = MutableStateFlow<Foo>(Foo.Loading)
override val uiState: StateFlow<Foo> = _uiState
private val _sideEffect = MutableSharedFlow<Foo2>()
override val sideEffect : SharedFlow<Foo2> = _sideEffect
}
init {
scope.launch {
usecase.getBar().fold(
onSuccess = { _uiState.emit(mapper(whatever))
if(...) _sideEffect.emit(whatever)
}
onFailure = { _uiState.emit(handleError(it)) }
}
}
I'm trying to handle these emit, but I'm not succeeding I'm trying with the library app.cash.turbine but is throwing me an error...
kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 1000 ms
(Coroutine boundary)What I'm doing in the test is :
@Test
fun test() {
//given with the usecase call and willReturn what I want
//given with the mapper call and willReturn what I want
//Init presenter so the init {} method gets fired
presenter.uiState.test {
assertEquals(WhatIExpect, awaitItem())
awaitComplete()
}
But it's not working, is there something I'm missing?Nick Allen
12/15/2021, 5:24 PMcancelAndIgnoreRemainingEvents()
method you may want instead of awaitComplete()
.Pablo
12/18/2021, 6:45 PMpresenter.uiState.test{...}