Compose Unstyled 2.0 is out! Check the official announcement blog ->
Function

assertContentDescriptionContains

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

assertContentDescriptionContainsSample

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)
}

Last updated: