ursus
03/30/2021, 3:37 AMfun <T> Flow<T>.test(scope: CoroutineScope): TestCollector<T> {
return TestCollector(scope, this)
}
class TestCollector<T>(
scope: CoroutineScope,
flow: Flow<T>
) {
private val values = mutableListOf<T>()
init {
scope.launch {
flow.collect {
values += it
}
}
}
fun assertValues(vararg values: T) {
assertEquals(values.toList(), this.values)
}
}
quick and dirty of how it worked in rx -- see anything wrong with it?