Pablo
05/11/2022, 9:49 AMviewModel
have the call in the init{}
? Because the way to test in turbine is to create the viewModel
and then get the sharedStateFlow
and do the calls of the viewModel
but what if the code is in init
when creating the viewModel
is already called this init
so I can not test the first state of this sharedFlow
right?
Example :
@Test
fun test = runTest {
val viewModel = createViewModel() <-- already call the init
viewModel.stateFlow.test {
//What should I call here? If it's in init...
}
}
jean
05/11/2022, 10:52 AMinit
by calling awaitItem()
jean
05/11/2022, 10:57 AMStateFlow
to a regular Flow
to prevent emitted values to be skipped if your init emit several values in a short time.Adam Powell
05/11/2022, 2:30 PM