When use liveData and change to flow by .asFlow() test won't trigger events
See original GitHub issueHi I have an issue when convert live data to flow like:
fun foo(
): Flow<B> =
bar().asFlow()
.map { -> }
foo().test{
val result = awaitItem()
Assert.assertEquals(expected, result)
awaitComplete()
}
Then I got this error
After waiting for 60000 ms, the test coroutine is not completing, there were active child jobs: [ScopeCoroutine{Active}@35c3ef4a]
Previously I faced this issue and find out that in some case should awaitComplete()
but it some case that will also not works.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Android Turbine won't triggers event from liveData that ...
Turbine is very handily tool for test flows. But I have an issue when convert live data to flow like: fun foo( ):...
Read more >Kotlin's Flow in ViewModels: it's complicated - Christophe Beyls
Keep using LiveData in your Android UI layer and ViewModels, especially for triggers. Use it whenever possible to expose data to be consumed...
Read more >Learn advanced coroutines with Kotlin Flow and LiveData
In this codelab, you'll learn how to use the LiveData builder to combine Kotlin coroutines with LiveData in an Android app. We'll also...
Read more >LiveData vs SharedFlow and StateFlow in MVVM and MVI ...
It is simply not enough, since Flow has a subscription count property that won't be changed when Lifecycle.Event reaches ON_STOP. This means ...
Read more >How I Solved This: Test Flows and Processes Without ...
Learn how Salesforce Admin Gordon Lee created a custom text field that allows him to run flows and processes without updating live data....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have never used LiveData. Can you provide a self-contained failing test case?
Thanks for response, for minimizing the question I did not pass dispatchers and as long as no dispatcher change I think
runTest
should be fine. So in my real code I’m doing something very same. May missed part isInstantTaskExecutorRule
But I got error on your code:Could you check if you see same issue?