LeoColman/kotest-android
View on GitHubSupport matching string resources in assertions
Open
#33 opened on Jan 6, 2025
enhancementgood first issue
Repository metrics
- Stars
- (36 stars)
- PR merge metrics
- (PR metrics pending)
Description
infix fun TextView.shouldHaveText(text: String) = this should haveText(text)
infix fun TextView.shouldNotHaveText(text: String) = this shouldNot haveText(text)
fun haveText(text: String) = object : Matcher<TextView> {
override fun test(value: TextView) = MatcherResult(
text.contentEquals(value.text),
"TextView should have text $text but was ${value.text}",
"TextView should not have text $text, but had"
)
}
This matcher requires a hardcoded String to check text, but TextViews often get their text from string resources. String resources can also have formatting tags, which makes comparing to a hardcoded String impractical. There should be a way to compare text and string attributes with string resources. This goes for other matchers that compare text too, such as View.hasContentDescription.