Function

assertContentDescriptionContains

Asserts that the node's list of content descriptions contains the given value.

assertContentDescriptionContainsSample

@Sampled
fun assertContentDescriptionContainsSample() {
    composeTestRule.setContent {
        // Explicitly merging descendants to demonstrate list semantics
        Row(Modifier.semantics(mergeDescendants = true) { testTag = "iconRow" }) {
            Icon(ColorPainter(Color.Red), contentDescription = "Navigate Up")
            Icon(ColorPainter(Color.Yellow), contentDescription = "Go Home")
        }
    }

    // The merged content description list is: ["Navigate Up", "Go Home"]

    // "Navigate Up" is an exact match for one of the items in the list.
    composeTestRule.onNodeWithTag("iconRow").assertContentDescriptionContains("Navigate Up")

    // "Navigate" is a substring of an item in the list, and we explicitly enable substring
    // matching.
    composeTestRule
        .onNodeWithTag("iconRow")
        .assertContentDescriptionContains("Navigate", substring = true)
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: