So, I am trying to use Turbine to test a flow that...
# coroutines
j
So, I am trying to use Turbine to test a flow that I receive from the VM... I have a initial state and after I call
viewModel.updateBrand()
I expect to receive a Loading and a revert to initial state in case of error... the problem is that the loading state is not being captured... any idea of how to fix it ? My VM is using
UnconfinedTestDispatcher
to execute coroutines/flows
Copy code
val flow = MutableStateFlow(true)
        coEvery { isSubscribedBrandUseCase.checkSubscribed(any()) } returns flow
        coEvery { unsubscribeToBrandUseCase(any()) } throws Exception()
        val brand = FavoriteBrand(
            brandId = "brandId",
            label = "label",
            heartState = HeartState.Subscribed
        )
        val viewModel = BrandRowViewModel(
            subscribeToBrandUseCase,
            unsubscribeToBrandUseCase,
            isSubscribedBrandUseCase,
            brand,
            TestSchedulerProvider(dispatcher = UnconfinedTestDispatcher()),
        )
        viewModel.viewState.test {
            assertEquals(
                awaitItem(),
                BrandState.PublishBrand(brand),
                "Initial Value"
            )

            assertEquals(
                awaitItem(),
                BrandState.PublishBrand(brand.copy(heartState = HeartState.Loading)),
                "Loading state while updating brand"
            )

            assertEquals(
                awaitItem(),
                BrandState.PublishBrand(brand),
                "Revert state because of the error"
            )

        }
        viewModel.updateBrand(brand)
    }