Anyone know if there’s any easy way to get a robol...
# compose
m
Anyone know if there’s any easy way to get a robolectric test to wait for a coroutine launched by a “rememberCoroutineScope” scope?
z
I think you’d need to register your own idling resource. Animations do this automatically, but if you’re launching your own coroutines you probably need to do it yourself.
m
For expresso tests, yes @Zach Klippenstein (he/him) [MOD]. This is in a robolectric test, which does’t necessarily use idling resources. I have that already, and have a rule i can use in an espresso test. But this is robolectric not espresso
I suppose i could sort of manually simulate it:
Copy code
runBlocking {
            while (!EspressoIdlingResource.getIdlingResource().isIdleNow()) {
                delay(100L)
            }
        }
z
oh sorry, misread.
yea i’m not sure for robolectric
m
I’m also having problems with the viewpager and figuring out what’s visible
j
If you’re not swapping dispatchers it should just work fine,
rememberCoroutineScope
should be using
TestCoroutineDispatcher
in tests
m
It’s just odd @Jason Ankers because i’m using an animateScrollTo with a horizontal pager. That’s triggering a page change, which i’m listening to here:
Copy code
LaunchedEffect(pagerState) {
        snapshotFlow { pagerState.currentPage }.collect { page ->
            println("onPageChange ${items[page].page}")
            onPageChange(items[page].page)
        }
    }
but onPageChange isn’t firing immediate like i would think it would with a TestCoroutineDispatcher. If i put my condition checking for that execution later on in the code, it’s fine.
I’m also struggling to figure out how to test that the right pager contents are on screen,s icne the semantic tree for the pager doesn’t seem to tell me that.