How can I test MutableSharedFlow<Unit>() with turbine ? #116
Unanswered
ismailtosun
asked this question in
Q&A
Replies: 1 comment
-
What you wrote looks fine. There is no real way to test the absence of an emission since your code could emit an item a millisecond later. All you can assert in the negative is that no events have been seen up until the current point in time. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
when i press button MutableSharedFlow() is emiting. So how can i test this with turbine emiting or not ?
// in ViewModel
private val _updateAddress = MutableSharedFlow()
val updateAddress = _updateAddress.asSharedFlow()
fun updateAddressClick() {
viewModelScope.launch {
_updateAddress.emit(Unit)
}
}
//Test Class
@test
fun updateAddressBtn_clickEvent_Emiting_or_Not() = runTest {
viewModel.updateAddress.test {
// given
// when
viewModel.updateAddressClick()
// then
Truth.assertThat(awaitEvent())
}
}
Beta Was this translation helpful? Give feedback.
All reactions