Function

assertTextContains

Asserts that the node's list of text values contains the given value.

assertTextContainsSample

@Sampled
fun assertTextContainsSample() {
    composeTestRule.setContent {
        // Explicitly merging descendants to demonstrate list semantics
        Row(Modifier.semantics(mergeDescendants = true) { testTag = "textRow" }) {
            Text("Hello")
            Text("World")
        }
    }

    // The merged text list is: ["Hello", "World"]

    // "Hello" is an exact match for one of the items in the list.
    composeTestRule.onNodeWithTag("textRow").assertTextContains("Hello")

    // "Hel" is a substring of an item in the list, and we explicitly enable substring matching.
    composeTestRule.onNodeWithTag("textRow").assertTextContains("Hel", 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: