If anyone has experience with turbine and mutable state flow. Why would this work:
Copy code
val mutableSharedFlow = MutableSharedFlow<Int>()
mutableSharedFlow.test {
mutableSharedFlow.emit(1)
assertEquals(awaitItem(), 1)
}
and this does not work:
Copy code
runTest(UnconfinedTestDispatcher()) {
val bleAdapterEnabledFlow = MutableStateFlow(false)
val stateFlow = bleAdapterEnabledFlow.stateIn(this)
stateFlow.test {
bleAdapterEnabledFlow.emit(true)
assertEquals(awaitItem(), true)
}
}
a
Adam S
01/09/2023, 11:46 AM
this channel is for MockK, which I don’t think is what you’re asking about? You might have a better chance of an answer in a more related channel like #coroutines
e
Eduard Boloș
01/09/2023, 5:54 PM
@Adam Pelsoczi not sure why it doesn't work, but why would you even do
.stateIn()
on a MutableStateFlow? Maybe you want to do
.asStateFlow()
instead if you want to make it non-mutable?
a
Adam Pelsoczi
01/09/2023, 7:38 PM
I wanted it to be mutablestate flow because I had a function which returns a combine() flow from various flows bleAdapterEnabledFlow and bleConnectionFlow, but the actual problem was that I had a class which had two dependency injections injected, and those were mockk and I had every mockk returns either flows. Anyways the problem was that I had the class under test instantiated in the
Before
annotation and then I was calling
every { injected.flow } returns mutabableStateFlow
. So when I wrote mutableStateFlow.emit() the emissions weren't happening