Hi all. I'm rendering UI composables conditionally...
# compose-android
a
Hi all. 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. See error and more details in 🧵
Error:
Copy code
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:
Copy code
ParentComposable(
    <parameters>,
    content = {
        when (uiState) {
            is UiState.Loading -> {
                LoadingScreen(
                    modifier =
 Modifier.testTag("string")
                )
            }
        }
    }
)
LoadingScreen
composable fails to be found. I tried the execution of assertion with
useUnmergedTree
set to
true
but that fails too.
I'm `mockk`ing 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.
a
you can print the merged and unmerged tree and see where that test tag is coming? If it is coming in the unmerged tree you need to query in by passing the
unmerged = true