koufa
07/11/2019, 12:17 PMflowOf("one string", "second string", "third string")
.debounce(300)
.map { it.trim() }
.filter { it.length > 2 }
.flowOn(Dispatchers.Default)
.distinctUntilChanged()
.switchMap {
// Simulate server call
delay(2000)
flow {
// Just return search term for the moment
emit(it)
}
}
.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
.collect {
_viewState.value = it
}
Now I want to define a unit test for that but I am not sure how to do this for the above flow. Do I need to extract the flow except from the collector
at the end to a function and then add a test collector
and verify the values I would expect to get there? Or is there any other idiomatic way?streetsofboston
07/12/2019, 6:10 PMstreetsofboston
07/12/2019, 6:12 PM_viewState
and verify if its value
is called with the correct values (in the correct order).
Since you hard-coded the Dispatchers, wrap the entire call into a runBlocking { ... }
and when that one returns, assert/verify the _viewState.value
.