Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing text in TextSpan

Tags:

flutter

dart

If we have a TextSpan that is a child of a RichText widget, how would you test the text content.

new TextSpan(
  text: 'Hello world!',
  style: new TextStyle(color: Colors.black),
)

In your tests, with a Text widget, you can use expect(find.text('Hello world!'), findsOneWidget), but this doesn't work if you have a TextSpan.

expect(find.byType(TextSpan), findsOneWidget) also does not find any widgets of type TextSpan.

like image 538
S.D. Avatar asked Jul 09 '18 05:07

S.D.


People also ask

What is text span?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute.


1 Answers

That's not possible. As TextSpan doesn't actually render anything. It is data information used by another object to actually render something.

What you can do instead is to find the widget to which you pass your TextSpan. And then verify it's correct

like image 171
Rémi Rousselet Avatar answered Oct 19 '22 10:10

Rémi Rousselet