I have a Switch in a composable:
Switch(
checked = false,
modifier = Modifier.testTag("mySwitch")
)
And I'm trying to verify it from a compose unit test:
composeTestRule.onAllNodesWithTag("mySwitch")
.assertAll(isToggleable() and isOff())
However it fails with the following exception:
java.lang.AssertionError: Failed to assertAll((ToggleableState is defined) && (ToggleableState = 'Off'))
Found '1' nodes not matching:
1) Node #8 at (l=955.0, t=387.0, r=1054.0, b=450.0)px, Tag: 'switch'
Has 4 siblings
Selector used: 'TestTag = 'mySwitch''
Apparently the Switch is neither toggleable or "on/off-eable". I've checked also with assertIsToggleable
and assertIsOff
separately, and both fail.
I've verified that the Switch is visible for the UI state used in the test.
Why does my test fail? It should be possible to easily test a freaking Switch. A Switch is the very definition of "Toggleable". How could I test it then, should I use custom semantic properties?
DISCLAIMER: This question is not the same as this one. I want to verify the Switch state, not to click it (that I will try later)
Switch
from on to off in the test. – Quartile