Skip to content

Instantly share code, notes, and snippets.

@dladukedev
Created July 25, 2023 15:15
Show Gist options
  • Save dladukedev/f1563dc712fcf41ae6a4914a52ba78bf to your computer and use it in GitHub Desktop.
Save dladukedev/f1563dc712fcf41ae6a4914a52ba78bf to your computer and use it in GitHub Desktop.
Mockup showing the issue with combine where Turbine misses elements
@Test
fun `this test fails`() = runTest {
val number = (0..2).asFlow()
val intro = listOf("Hello").asFlow()
val combined = combine(intro, number) { first, second ->
"$first $second"
}
combined.test {
assertEquals("Hello 0", awaitItem())
assertEquals("Hello 1", awaitItem())
assertEquals("Hello 2", awaitItem())
awaitComplete()
}
}
@Test
fun `this test succeeds`() = runTest {
val number = (0..2).asFlow().onEach { delay(1) }
val intro = listOf("Hello").asFlow()
val combined = combine(intro, number) { first, second ->
"$first $second"
}
combined.test {
assertEquals("Hello 0", awaitItem())
assertEquals("Hello 1", awaitItem())
assertEquals("Hello 2", awaitItem())
awaitComplete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment