I'm trying to test accompanist PagerState
.
The author has already added tests (https://github.com/google/accompanist/blob/main/pager/src/sharedTest/kotlin/com/google/accompanist/pager/PagerStateUnitTest.kt), however he uses scrollToPage
, but I need to use animateScrollToPage
.
But when i replace the scrollToPage
with the animateScrollToPage
(change_pager_count
test) I get exception:
java.lang.IllegalStateException: A MonotonicFrameClock is not available in this CoroutineContext. Callers should supply an appropriate MonotonicFrameClock using withContext.
I tried to remember coroutine scope and run animateScrollToPage
inside this scope:
composeTestRule.setContent {
scope = rememberCoroutineScope()
.....
}
composeTestRule.runOnIdle {
scope.launch {
pagerState.animateScrollToPage(page = 8)
}
}
// And assert that currentPage and pageCount are correct
assertThat(pagerState.currentPage).isEqualTo(8)
assertThat(pagerState.pageCount).isEqualTo(10)
But I still get this exception.
Please help me figure out what I'm doing wrong.