Skip to content

Instantly share code, notes, and snippets.

@oliverspryn
Created September 5, 2025 14:33
Show Gist options
  • Save oliverspryn/810e2630deef76b3e8ddab91bf48d37a to your computer and use it in GitHub Desktop.
Save oliverspryn/810e2630deef76b3e8ddab91bf48d37a to your computer and use it in GitHub Desktop.
Custom assertions for testing Jetpack Compose custom action labels and callbacks
fun SemanticsNodeInteraction.assertHasCustomActionLabel(
label: String, // Assert the label matches
actionIndex: Int = 0 // Which action to verify, if you have more than one
): SemanticsNodeInteraction = assert(SemanticsMatcher("The custom accessibility action label is set to $label") {
it.config
.getOrNull(SemanticsActions.CustomActions)
?.get(actionIndex)?.label == label
})
fun SemanticsNodeInteraction.invokeCustomAction(
actionIndex: Int = 0 // Which action to invoke, if you have more than one
): SemanticsNodeInteraction = assert(SemanticsMatcher("The custom accessibility action is invoked") {
val action = it.config
.getOrNull(SemanticsActions.CustomActions)
?.get(actionIndex)?.action ?: return@SemanticsMatcher false
action.invoke()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment