You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I want to test that this Widget is visible, I'd normally use
// password_text_field_test.darttestWidgets(
'tapping on password visibility button toggles it',
(tester) async {
final eyeFinder = find.widgetWithIcon(IconButton, FontAwesomeIcons.eye);
expect(eyeFinder, findsOneWidget);
});
But the above will fail:
tapping on password visibility button toggles it
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _AncestorFinder:<zero widgets with type "IconButton" which is an ancestor of icon
"IconData(U+0F06E)">
Which: means none were found but one was expected
The reason is that FaIcon is not an Icon (i.e FaIcon extends StatelessWidget), so find.widgetWithIcon can't find it.
The problem
Let's say that I have the following Widget:
If I want to test that this Widget is visible, I'd normally use
But the above will fail:
The reason is that
FaIcon
is not anIcon
(i.eFaIcon extends StatelessWidget
), sofind.widgetWithIcon
can't find it.The solution 1/2
To make
find.widgetWithIcon
work withFaIcon
, we have to create a custom implementation of Flutter'sWidgetIconFinder
:Then, to make it shorter for use in tests, we can create our own
CustomFinders
class, basing on Flutter'sCommonFinders
:The solution 2/2
Then, we can use our custom finders just like we'd use the default ones
Further steps
I see 2 ways:
FaIcon
(maybe link to this issue?)The text was updated successfully, but these errors were encountered: