I would like to test what was emited by my viewModel. In viewModel I have:
fun setTitle(){
viewModelScope.launch {
batchEntity ?. let{
titleChannel.send(UiText.StringResource(R.string.edit_batch_title))
} ?: let{
titleChannel.send(UiText.StringResource(R.string.add_batch_title))
}
}
}
In test I have:
@Test
fun getTitle_AddMode() {
runTest {
batchAddViewModel.title.collectLatest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertThat(it.asString(appContext)).isEqualTo(
UiText.StringResource(R.string.add_batch_title).asString(appContext)
)
}
}
}
Wherever I call viewModel.setTitle test is always waiting for emmision and it always fails