Add matcher to find at least a given number of widgets (#102081) (#102342)

This commit is contained in:
Daniel Cardona Rojas
2022-04-22 17:24:10 -05:00
committed by GitHub
parent 6ea4aef827
commit a3a9a23e46
2 changed files with 56 additions and 0 deletions

View File

@@ -674,6 +674,42 @@ void main() {
handle.dispose();
});
});
group('findsAtLeastNWidgets', () {
Widget boilerplate(Widget child) {
return Directionality(
textDirection: TextDirection.ltr,
child: child,
);
}
testWidgets('succeeds when finds more then the specified count',
(WidgetTester tester) async {
await tester.pumpWidget(boilerplate(Column(
children: const <Widget>[Text('1'), Text('2'), Text('3')],
)));
expect(find.byType(Text), findsAtLeastNWidgets(2));
});
testWidgets('succeeds when finds the exact specified count',
(WidgetTester tester) async {
await tester.pumpWidget(boilerplate(Column(
children: const <Widget>[Text('1'), Text('2')],
)));
expect(find.byType(Text), findsAtLeastNWidgets(2));
});
testWidgets('fails when finds less then specified count',
(WidgetTester tester) async {
await tester.pumpWidget(boilerplate(Column(
children: const <Widget>[Text('1'), Text('2')],
)));
expect(find.byType(Text), isNot(findsAtLeastNWidgets(3)));
});
});
}
enum _ComparatorBehavior {