Melih Aksoy
06/17/2019, 1:55 PMflow
, but having trouble test is finished before all emits happen.
Following code works all fine if I add a delay
after source.stateData.testObserve
@Test
@ExperimentalCoroutinesApi
fun `should update state after load initial`() {
val initialParams = mockk<PageKeyedDataSource.LoadInitialParams<Int>>(relaxed = true)
val initalCallback = mockk<PageKeyedDataSource.LoadInitialCallback<Int, String>>(relaxed = true)
runBlocking {
// Fake loading
source.loadInitial(initialParams, initalCallback)
source.stateData.testObserve {
it shouldBeInstanceOf Result.State::class
}
}
}
I don’t think this is the right way , how do I test a flow
correctly ? And since we’re on it, is there a way to verify a flow is collected / collected n times etc. ?testObserve
suspending and called suspendCoroutine
on it, and calling resume
of continuation
when I post values to live data, seems to solve it without a random delay / wait.