Alex Styl
@Test fun assertTextIsRed() = runComposeUiTest { setContent { Text("Hello World", color = Color.Red) } onNodeWithText("Hello World") .assertTextStyle { it.color == Color.Red } } private fun SemanticsNodeInteraction.assertTextStyle(matcher: (TextStyle) -> Boolean): SemanticsNodeInteraction { return this.assert( SemanticsMatcher("TextStyle") { node -> val textLayoutResults = mutableListOf<TextLayoutResult>() node.config[SemanticsActions.GetTextLayoutResult].action?.invoke(textLayoutResults) if (textLayoutResults.isNotEmpty()) { val textStyle = textLayoutResults[0].layoutInput.style matcher(textStyle) } else { false } } ) }
A modern programming language that makes developers happier.