Skip to content

How can I test MutableSharedFlow<Unit>() with turbine ?  #115

Description

@ismailtosun

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())
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions