If anyone has experience with turbine and mutable ...
# mockk
a
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
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
@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
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
329 Views