Hi I am trying to write some unit test cases for the Stateflow and Flow in Kotlin Multiplatform,
My requirement is
val loader = MutableStateFlow(false)
suspend fun fetchBugs(bugsParams: BugsApiRequestParams) {
val responseObject = remoteDataSource.getBugsFromTheServer(bugsParams)
loader.value = true
if (responseObject.isResponseArrayInitialized()) {
val bugs = mapper.mapBugs(responseObject, bugsParams.portalId, bugsParams.projectId)
localDataSource.insertOrUpdate(bugs)
}
loader.value = false
}
I want to check all the values emitted by the flow in the fetchBugs call, and I have tried to convert the flow into a list but of no use
@Test
fun makeTheLoaderToTrueWhenBeforeItHitServer()= runBlocking{
val repository = mockSuccessfulCase()
repository.fetchBugs(bugsParams)
assertEquals(false , repository.loader.first())
}
Is there any way to check it? Thanks in advance :)