How can I best use turbine to verify the eventual ...
# squarelibraries
a
How can I best use turbine to verify the eventual value of a StateFlow? If I use
awaitItem()
I seem to see each individual time the StateFlow was set, but what I care about is the eventual value after a number of operations. It manifests most painfully in my combine-heavy view model with a lot of
.stateIn()
operations but can also be seen in
Copy code
val stateFlow = MutableStateFlow(false)
stateFlow.test {
  stateFlow.value = true
  val a = awaitItem() // this is false
  val b = awaitItem() // this is true
}
t
Is the eventual value unique compared to the intermediate ones? If so, and your test is to ensure the flow reaches that state, you can to
stateFlow.filter{}.test{ awaitItem() }
where you use filter to remove the noise that isn't important for the test
a
It's not necessarily unique. In this case it's deciding whether to show some Android UI based on a number of other flows (some mutablestateflows, some database-driven) so it might stay at its initial value of false or might change to true.
e
how long is "eventual"?
you could
Copy code
delay(100)
expectMostRecentItem()
with caveats about timing
a
They're the result of a combine operation across a number of other flows (up to 8 in some cases) so it's a short period of time but potentially a number of updates.