Finding text on screen during widget tests is crucial. It's by far the easiest way to navigate through an app. Therefore, a good API for text is extremely important and justifies a breaking change.
Text is different from widgets.
With widgets you want to have the exact type and fire assertions against it. Static typing is key.
Text may be presented by different widgets. Text, SelectableText, EditableText or RichText. But regardless of the Widget presenting the text, you want to fire the same assertions against it.
This PR introduces AnyText, an artificial widget combining properties of all known Text presenting widgets.
The new spotText() returns SingleWidgetSelector<AnyText>.
spotText('foo').existsOnce();
Some features about spotText:
matches via "contains" by default. This means you can find the text "John Doe" on screen with a Text("User: John Doe ⭐️")
Allows matching regular expressions like spotText(RegEx(r"J.* Doe")); matching "John Doe" and "Jane Doe"
Returns only a single widget. When multiple widgets match, it throws an exception
If you're interested in the properties of the actual text widget that presents the text use the normal spot method with the generic type T, e.g. Text:
// deprecated
spotSingleText("Hello");
spotSingleText<Text>("Hello");
spotTexts<EditableText>("Hello");
// New
spotText("Hello");
spotText("Hello", exact: true);
spotTextWhere((it) => it.startsWith("He"));
// With exact widget type
spot<Text>().whereText((it) => it.equals("Hello")).first();
Finding text on screen during widget tests is crucial. It's by far the easiest way to navigate through an app. Therefore, a good API for text is extremely important and justifies a breaking change.
Text is different from widgets. With widgets you want to have the exact type and fire assertions against it. Static typing is key.
Text may be presented by different widgets.
Text
,SelectableText
,EditableText
orRichText
. But regardless of the Widget presenting the text, you want to fire the same assertions against it.This PR introduces
AnyText
, an artificial widget combining properties of all known Text presenting widgets.The new
spotText()
returnsSingleWidgetSelector<AnyText>
.Some features about
spotText
:Text("User: John Doe ⭐️")
spotText(RegEx(r"J.* Doe"));
matching "John Doe" and "Jane Doe"If you're interested in the properties of the actual text widget that presents the text use the normal
spot
method with the generic typeT
, e.g.Text
: