dambakk
09/21/2021, 8:18 AMTestNavHostController
as NavHostController
parameter (defaults to rememberAnimatedNavController
) but get an exception when the building the navgraph:
androidx.navigation.testing.TestNavigatorProvider$navigator$1 cannot be cast to com.google.accompanist.navigation.animation.AnimatedComposeNavigator
at com.google.accompanist.navigation.animation.NavGraphBuilderKt.composable(NavGraphBuilder.kt:124)
Doesnt the accompanist nav animation lib support testing yet?
(code in 🧵)dambakk
09/21/2021, 8:24 AM@OptIn(ExperimentalAnimationApi::class)
@Composable
fun FeedbackRoot(
navController: NavHostController = rememberAnimatedNavController(),
viewModel: FeedbackViewModel = viewModel()
) {
...
AnimatedNavHost(
navController = navController,
startDestination = "feedbackTypePicker",
) {
composable(
route = "feedbackTypePicker",
The exception is thrown from the first call to composable
in the lambda of the AnimatedNavHost.
The test:
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun feedbackScreen_clickingTypeNavigatesToCategoryScreen() {
val navController = TestNavHostController(ApplicationProvider.getApplicationContext())
composeTestRule.setContent {
NTTheme {
FeedbackRoot(
navController = navController,
viewModel = feedbackViewModel,
onFinish = {}
)
}
}
...
}
dambakk
09/21/2021, 8:46 AM@get:Rule
val composeTestRule = createComposeRule()
instead of
val composeTestRule = createAndroidComposeRule<FeedbackActivity>()
fixed my issues. I thought I had to inject a TestNavHostController
instance instead of using the default AnimatedNavHostController
, but apparently not, the test runs just fine with it 🙂