Is it possible to assert that a jetpack compose node is scrollable when performing tests?
class MyTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun givenEnoughItems_thenAssertListIsScrollable() {
composeTestRule.setContent {
BasicTheme {
ScrollableComponent(items = List(1000) { "$it" })
}
}
composeTestRule.onRoot().fetchSemanticsNode().assertIsScrollable()
}
}
fun SemanticsNodeInteraction.assertIsScrollable() : SemanticsNodeInteraction {
// What would go here?
}
Use hasScrollAction().
Example
import androidx.compose.ui.test.hasScrollAction
import androidx.compose.ui.test.assert
private fun assertNodeIsScrollable() {
findNode().assert(hasScrollAction())
}
and findNode() would be something like
private fun findNode(): SemanticsNodeInteraction {
return composeTestRule.onNodeWithTag(
testTag = "test_tag",
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With