Skip to content

Instantly share code, notes, and snippets.

@chao2zhang
Last active June 23, 2021 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chao2zhang/77c48981e4dd03e31c6f66c68b1bfd2a to your computer and use it in GitHub Desktop.
Save chao2zhang/77c48981e4dd03e31c6f66c68b1bfd2a to your computer and use it in GitHub Desktop.
Test Flow.asLiveData() for hot flow
@Test
fun testDefaultTimeout() = runBlockingTest {
val source = MutableStateFlow(1)
val liveData = source.asLiveData()
val observer = object : Observer<Int> {
var observeHistory = mutableListOf<Int>()
override fun onChanged(t: Int) {
observeHistory.add(t)
}
}
// Observe
liveData.observeForever(observer)
// Clear observers
liveData.removeObserver(observer)
// Assertions
assertEquals(listOf(1), observer.observeHistory)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment