vide
03/14/2024, 9:29 AMvide
03/14/2024, 9:30 AMval flow = MutableStateFlow(0)
val testScope = TestScope()
val defaultScope = CoroutineScope(Dispatchers.Default)
val values = mutableListOf<Int>()
testScope.launch { flow.collect { values.add(it) } }
repeat(1000) { n ->
defaultScope.launch { flow.value = n }
runBlocking { flow.first { it == n } }
testScope.testScheduler.runCurrent()
assertEquals(values[n], n)
}
vide
03/14/2024, 9:31 AMrunCurrent()
until it's done but I'm wondering if there's any other way.vide
03/14/2024, 9:38 AMdefaultScope
is not really part of the test, it is some external code listening for updates on a websocket connection. The test actually works like:
// mock update to websocket
flow.first { it == n }
testedScheduler.runCurrent()
// assert ui has updated