juliocbcotta
05/04/2023, 12:55 PMviewModel.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
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)
}