# GlanceNodeAssertion

# GlanceNodeAssertion

Artifact:[androidx.glance:glance-testing](https://developer.android.com/jetpack/androidx/releases/glance)  
[View Source](https://cs.android.com/search?q=file:androidx/glance/testing/GlanceNodeAssertion.kt+class:androidx.glance.testing.GlanceNodeAssertion)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/glance#1.1.0)

<br />

```
class GlanceNodeAssertion<R : Any?, T : GlanceNode<R>>
```

<br />

*** ** * ** ***

Represents a Glance node from the tree that can be asserted on.

An instance of[GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion)can be obtained from`onNode`and equivalent methods on a[GlanceNodeAssertionsProvider](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionsProvider)

## Summary

|                                                             ### Public functions                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion)`<R, T>`                     | [assert](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion#assert(androidx.glance.testing.GlanceNodeMatcher,kotlin.Function0))`(matcher: `[GlanceNodeMatcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeMatcher)`<R>, messagePrefixOnError: (() `->` `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)?)` Asserts that the provided[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion#assert(androidx.glance.testing.GlanceNodeMatcher,kotlin.Function0))is satisfied for this node. |
| [GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion)`<R, T>`                     | [assertDoesNotExist](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion#assertDoesNotExist())`()` Asserts that no matching node was found.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion)`<R, T>`                     | [assertExists](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion#assertExists())`()` Asserts that the node was found.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)`<R, T>` | [onChildren](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion#onChildren())`()` Returns[GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)that allows performing assertions on the children of the node selected by this[GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion).                                                                                                                                                                                    |

## Public functions

### assert

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/glance#1.1.0)  

```
fun assert(
    matcher: GlanceNodeMatcher<R>,
    messagePrefixOnError: (() -> String)? = null
): GlanceNodeAssertion<R, T>
```

Asserts that the provided[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion#assert(androidx.glance.testing.GlanceNodeMatcher,kotlin.Function0))is satisfied for this node.

This function also can be used to create convenience "assert{somethingConcrete}" methods as extension functions on the GlanceNodeAssertion.  

|                                                          Parameters                                                           |
|-------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `matcher: `[GlanceNodeMatcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeMatcher)`<R>` | Matcher to verify.                                                                                                                                                                                                       |
| `messagePrefixOnError: (() `->` `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)? = null` | Prefix to be put in front of an error that gets thrown in case this assert fails. This can be helpful in situations where this assert fails as part of a bigger operation that used this assert as a precondition check. |

|                                                  Throws                                                   |
|-----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [kotlin.AssertionError](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html) | if the matcher does not match or the node can no longer be found. |

### assertDoesNotExist

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/glance#1.1.0)  

```
fun assertDoesNotExist(): GlanceNodeAssertion<R, T>
```

Asserts that no matching node was found.  

|                                                  Throws                                                   |
|-----------------------------------------------------------------------------------------------------------|----------------------|
| [kotlin.AssertionError](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html) | if the assert fails. |

### assertExists

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/glance#1.1.0)  

```
fun assertExists(): GlanceNodeAssertion<R, T>
```

Asserts that the node was found.  

|                                                  Throws                                                   |
|-----------------------------------------------------------------------------------------------------------|----------------------|
| [kotlin.AssertionError](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html) | if the assert fails. |

### onChildren

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/glance#1.1.0)  

```
fun onChildren(): GlanceNodeAssertionCollection<R, T>
```

Returns[GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)that allows performing assertions on the children of the node selected by this[GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion).