Hi I want to test a Composable node is toggleable...
# compose
c
Hi I want to test a Composable node is toggleable, but the test fails.
Copy code
@Composable
    fun CheckBox() {
        Box(
            modifier = Modifier
                .size(32.dp)
                .background(Color.Red)
                .toggleable(
                    value = true,
                    enabled = true,
                    role = Role.Checkbox,
                    onValueChange = {}
                )
        )
    }

    @Test
    fun testToggleableCheckBox() {
        composeTestRule.setContent {
            CheckBox()
        }

        composeTestRule
            .onRoot()
            .assertIsToggleable()
    }
Copy code
java.lang.AssertionError: Failed to assert the following: (ToggleableState is defined)
Semantics of the node:
Node #1 at (l=0.0, t=279.0, r=84.0, b=363.0)px
Has 1 child
Selector used: (isRoot)
Even though the layout inspector says the ToggleableState is on. What I am missing?
z
I think the problem is that you’re selecting the root node, which is the root of the composition, not your
Box
1
c
You're right, thank you! 👍