---
title: "assertTextContains"
description: "Asserts that the node's list of text values contains the given value."
type: "function"
lastmod: "2026-06-18T10:32:52.770658Z"
---
## API Reference

### assertTextContains

> Source set: Common

```kotlin
fun SemanticsNodeInteraction.assertTextContains(
    value: String,
    substring: Boolean = false,
    ignoreCase: Boolean = false,
): SemanticsNodeInteraction
```

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

This will also search in [SemanticsProperties.EditableText](/jetpack-compose/androidx.compose.ui/ui/properties/editableText) and [SemanticsProperties.InputText](/jetpack-compose/androidx.compose.ui/ui/properties/inputText).

The `Text` property is represented as a list of strings. In the merged semantics tree (the
default in Compose testing), this list often contains multiple text items merged from child
nodes. This function evaluates whether any individual item in that list matches the provided
`value`.

By default, this requires an exact string match with at least one complete item in the list.

Typically, accessibility tooling will decide based on its heuristics which ones to use.

Throws `AssertionError` if the node's value list does not contain `value`, or if the node has no
value.

#### Parameters

| | |
| --- | --- |
| value | Value to match against the items in the list of text values. |
| substring | Whether this can be satisfied as a substring match of an item in the list of text. Defaults to false. |
| ignoreCase | Whether case should be ignored. Defaults to false. |

## Code Examples
### assertTextContainsSample
```kotlin
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)
}
```
