# GlanceNodeAssertionCollection

# GlanceNodeAssertionCollection

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/GlanceNodeAssertionCollection.kt+class:androidx.glance.testing.GlanceNodeAssertionCollection)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/glance#1.1.0)

<br />

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

<br />

*** ** * ** ***

Represents a collection of Glance nodes from the tree that can be asserted on.

An instance of[GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)can be obtained from[GlanceNodeAssertionsProvider.onAllNodes](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionsProvider#onAllNodes(androidx.glance.testing.GlanceNodeMatcher))and equivalent methods.

## Summary

|                                                             ### Public functions                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)`<R, T>` | [assertAll](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertAll(androidx.glance.testing.GlanceNodeMatcher))`(matcher: `[GlanceNodeMatcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeMatcher)`<R>)` Asserts that all the nodes in this collection satisfy the given[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertAll(androidx.glance.testing.GlanceNodeMatcher)).                     |
| [GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)`<R, T>` | [assertAny](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertAny(androidx.glance.testing.GlanceNodeMatcher))`(matcher: `[GlanceNodeMatcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeMatcher)`<R>)` Asserts that this collection contains at least one element that satisfies the given[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertAny(androidx.glance.testing.GlanceNodeMatcher)). |
| [GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)`<R, T>` | [assertCountEquals](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertCountEquals(kotlin.Int))`(expectedCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Asserts that this collection of nodes is equal to the given[expectedCount](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertCountEquals(kotlin.Int)).                                                                                        |
| [GlanceNodeAssertionCollection](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection)`<R, T>` | [filter](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#filter(androidx.glance.testing.GlanceNodeMatcher))`(matcher: `[GlanceNodeMatcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeMatcher)`<R>)` Returns a new collection of nodes by filtering the given nodes using the provided[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#filter(androidx.glance.testing.GlanceNodeMatcher)).            |
| `operator `[GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion)`<R, T>`          | [get](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#get(kotlin.Int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a[GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion)that can assert on the node at the given index of this collection.                                                                                                                                               |

## Public functions

### assertAll

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

```
fun assertAll(matcher: GlanceNodeMatcher<R>): GlanceNodeAssertionCollection<R, T>
```

Asserts that all the nodes in this collection satisfy the given[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertAll(androidx.glance.testing.GlanceNodeMatcher)).

Doesn't throw error if the collection is empty. Use[assertCountEquals](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertCountEquals(kotlin.Int))to assert on expected size of the collection.  

|                                                          Parameters                                                           |
|-------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| `matcher: `[GlanceNodeMatcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeMatcher)`<R>` | Matcher that has to be satisfied by all the nodes in the collection. |

|                                                  Throws                                                   |
|-----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| [kotlin.AssertionError](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html) | if the collection contains at least one element that does not satisfy the given matcher. |

### assertAny

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

```
fun assertAny(matcher: GlanceNodeMatcher<R>): GlanceNodeAssertionCollection<R, T>
```

Asserts that this collection contains at least one element that satisfies the given[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertAny(androidx.glance.testing.GlanceNodeMatcher)).  

|                                                          Parameters                                                           |
|-------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
| `matcher: `[GlanceNodeMatcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeMatcher)`<R>` | Matcher that has to be satisfied by at least one of the nodes in the collection. |

|                                                  Throws                                                   |
|-----------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [kotlin.AssertionError](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html) | if not at least one matching node was found. |

### assertCountEquals

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

```
fun assertCountEquals(expectedCount: Int): GlanceNodeAssertionCollection<R, T>
```

Asserts that this collection of nodes is equal to the given[expectedCount](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertCountEquals(kotlin.Int)).  

|                                                  Throws                                                   |
|-----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.AssertionError](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html) | if the size is not equal to[expectedCount](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#assertCountEquals(kotlin.Int)) |

### filter

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

```
fun filter(matcher: GlanceNodeMatcher<R>): GlanceNodeAssertionCollection<R, T>
```

Returns a new collection of nodes by filtering the given nodes using the provided[matcher](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertionCollection#filter(androidx.glance.testing.GlanceNodeMatcher)).  

### get

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

```
operator fun get(index: Int): GlanceNodeAssertion<R, T>
```

Returns a[GlanceNodeAssertion](https://developer.android.com/reference/kotlin/androidx/glance/testing/GlanceNodeAssertion)that can assert on the node at the given index of this collection.

Any subsequent assertion on its result will throw error if index is out of bounds of the matching nodes found from previous operations.