Last active
June 23, 2021 03:48
-
-
Save chao2zhang/77c48981e4dd03e31c6f66c68b1bfd2a to your computer and use it in GitHub Desktop.
Test Flow.asLiveData() for hot flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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