I have a composable that set the background color and I would like to test that.
@Composable
fun MyComposableButton(
enabledColor: Color,
disableColor: Color,
isEnabled: Boolean = true,
) {
val buttonBackgroundColor = if (enabled) enabledColor else disableColor
Button(
...
enabled = enabled,
colors = ButtonDefaults.textButtonColors(
backgroundColor = buttonBackgroundColor
)
) { ... }
}
I'm expecting to write a tests like: verifyEnabledBackgroundColor
and verifyDisabledBakcgroundColor
.
I can't find any assertion directly available on the compose testing, and when trying to create my own I find that the SemanticMatcther
uses a SemanticNode
, but the constructor is internal for the latest so that is no go.
I try to mock
the Color
but I couldn't and according to this answer high API level would be required, which is a no for my project.
How can I test setting the background color for a composable?