Simon Stahl
02/02/2022, 12:24 AMval ItemKey = SemanticsPropertyKey<Item>("Item")
var SemanticsPropertyReceiver.item by ItemKey
data class Item(val id: Int, val name: String)
Text(
modifier = Modifier.semantics {
this.testTag = "test"
this.item = Item(99, "TestXXX")
},
text = "My text"
)
And now in my test, I want to retrieve the Item
object and assert its values
composeTestRule.onNodeWithTag("test").assert(???, 99)
Anyone has a tip for how to do that?Zach Klippenstein (he/him) [MOD]
02/02/2022, 3:33 AMSimon Stahl
02/02/2022, 10:29 PMfun SemanticsNodeInteraction.assertItem(description: String, check: (Item) -> Boolean) {
assert(SemanticsMatcher(description) {
check(it.config[ItemKey])
})
}
composeTestRule.onNodeWithTag("test").assertItem("Checking id") {
it.id == 99
}