Marko Novakovic
10/23/2021, 2:14 PMViewModel
that exposes state with StateFlow
. I want to test that it emits Loading
state and than starting data fetching process from init
block. when I provide fake API I can’t catch Loading
state because data is fetched immediately and Success
state is emitted. how to test that Loading
comes first followed by Success
?Adam Powell
10/23/2021, 2:30 PMMarko Novakovic
10/23/2021, 2:33 PMScott Kruse
10/23/2021, 3:07 PMval stateList: MutableList<UiState> = mutableListOf()
val job = launch {
uiStateFlow.toList(stateList)
}
// do thing under test
stateList.size shouldEqual 2
stateList.first() shouldEqual Loading
stateList[1] shouldEqual Success
Marko Novakovic
10/23/2021, 3:13 PMMarko Novakovic
10/23/2021, 3:14 PMtoList()
Francesc
10/23/2021, 4:00 PMMarko Novakovic
10/23/2021, 9:46 PMDamian Zawadzki
10/24/2021, 7:18 AM