I'm rendering UI composables conditionally, based on UiState, however, tagging composables at the root with testTag doesn't make them findable in instrumentation tests.
Error:
java.lang.AssertionError: Failed: assertExists.
Reason: Expected exactly '1' node but could not find any node that satisfies: (TestTag = 'string')
The composable is passed as content parameter (content: @Composable () -> Unit) to another composable. The code is of the form:
ParentComposable(
<parameters>,
content = {
when (uiState) {
is UiState.Loading -> {
LoadingScreen(
modifier =
Modifier.testTag("string")
)
}
}
}
)
I'm mockking the UiState (it's stored in the ViewModel) so I'm sure I should be hitting the condition from this point of view. I even see the screen on my device and yet the test fails to find the node. Really at odds here how to fix this.
What I tried
LoadingScreen composable fails to be found. I tried the execution of assertion with useUnmergedTree
set to true but that fails too.
uiState
is actually equal toUiState.Loading
(you actually see this screen during the test)? In yourLoadingScreen
composable, are you applying the passed in modifier to another composable and not accidentally doingmodifier = Modifier
(notice the CAPITAL M)?UiState.Loading
- I actually see this screen during the test. And, yes, I'm applying the passed in modifier.