---
title: "SubspaceSemanticsNodeInteraction"
description: "Represents a semantics node and the path to fetch it from the subspace semantics tree."
type: "class"
lastmod: "2026-06-18T10:32:52.445276Z"
---
## API Reference

> Source set: Android

```kotlin
public class SubspaceSemanticsNodeInteraction
internal constructor(
    private val testContext: SubspaceTestContext,
    private val selector: SubspaceSemanticsSelector,
)
```

Represents a semantics node and the path to fetch it from the subspace semantics tree.

Allows performing assertions or retrieving the underlying semantics node information. An instance
of this class can be obtained from `onSubspaceNode` or convenience methods that use a specific
filter, such as `onSubspaceNodeWithTag`.

For real usage patterns and explicit semantic properties validation, see the referenced samples.

## Secondary Constructors

```kotlin
public constructor(
    testContext: SubspaceTestContext,
    matcher: SubspaceSemanticsMatcher,
) : this(testContext, SubspaceSemanticsSelector(matcher))
```

## Functions

### fetchSemanticsNode

```kotlin
public fun fetchSemanticsNode(errorMessageOnFail: String? = null): SubspaceSemanticsInfo
```

Returns the semantics node captured by this interaction.

This operation synchronizes with the UI to ensure the latest semantics tree data is fetched.
Since synchronization introduces performance overhead, it is recommended to cache the result
if accessed multiple times within a single atomic operation.

#### Parameters

| | |
| --- | --- |
| errorMessageOnFail | the prefix to be added to the error message if the fetch operation fails. Typically used by higher-level operations that rely on this fetch. |

#### Returns

| | |
| --- | --- |
|  | the underlying `SubspaceSemanticsInfo` corresponding to the matched node. |

### assertDoesNotExist

```kotlin
public fun assertDoesNotExist()
```

Asserts that no matching item was found or that the item is no longer in the hierarchy.

This operation synchronizes with the UI and fetches all nodes to ensure it has the latest
data. It is useful for verifying that an element has been correctly removed or was never
present.

### assertExists

```kotlin
@CanIgnoreReturnValue
public fun assertExists(errorMessageOnFail: String? = null): SubspaceSemanticsNodeInteraction
```

Asserts that the component was found and is part of the component tree.

This operation synchronizes with the UI and fetches all nodes to ensure it has the latest
data. Note that if you are already calling `fetchSemanticsNode`, calling this method is
redundant and introduces unnecessary overhead.

#### Parameters

| | |
| --- | --- |
| errorMessageOnFail | the prefix to be added to the error message if the assertion fails. Typically used by operations that rely on this assertion. |

#### Returns

| | |
| --- | --- |
|  | this interaction object to allow chaining of further assertions. |

## Code Examples

### subspaceNodeMatcherProperties
```kotlin
public fun subspaceNodeMatcherProperties() {
    composeTestRule.setContent {
        Subspace {
            SpatialPanel(SubspaceModifier.width(100.dp).height(100.dp).testTag("myPanel")) {}
        }
    }
    // Check existence and exact spatial dimensions in DP using semantic matchers
    composeTestRule
        .onSubspaceNodeWithTag("myPanel")
        .assertExists()
        .assertPositionInRootIsEqualTo(0.dp, 0.dp, 0.dp)
        .assertWidthIsEqualTo(100.toDp())
        .assertHeightIsEqualTo(100.toDp())
}
```

### subspacePanelRenderedAndInteractive
```kotlin
public fun subspacePanelRenderedAndInteractive() {
    var count = 0
    composeTestRule.setContent {
        Subspace {
            SpatialPanel(SubspaceModifier.testTag("spatialPanel")) {
                Button(onClick = { count++ }) { Text("Increment") }
            }
        }
    }
    // Assert subspace node existence, position, and dimensions in the Spatial hierarchy
    composeTestRule
        .onSubspaceNodeWithTag("spatialPanel")
        .assertExists()
        .assertPositionInRootIsEqualTo(0.toDp(), 0.toDp(), 0.toDp())
    // Interact with the 2D Compose node nested within the Spatial container
    composeTestRule.onNodeWithText("Increment").performClick()
    composeTestRule.waitForIdle()
    // Verify outcomes
    assert(count == 1)
}
```
