mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
This commit is contained in:
parent
6ea4aef827
commit
a3a9a23e46
@ -37,6 +37,7 @@ import 'widget_tester.dart' show WidgetTester;
|
||||
/// * [findsWidgets], when you want the finder to find one or more widgets.
|
||||
/// * [findsOneWidget], when you want the finder to find exactly one widget.
|
||||
/// * [findsNWidgets], when you want the finder to find a specific number of widgets.
|
||||
/// * [findsAtLeastNWidgets], when you want the finder to find at least a specific number of widgets.
|
||||
const Matcher findsNothing = _FindsWidgetMatcher(null, 0);
|
||||
|
||||
/// Asserts that the [Finder] locates at least one widget in the widget tree.
|
||||
@ -52,6 +53,7 @@ const Matcher findsNothing = _FindsWidgetMatcher(null, 0);
|
||||
/// * [findsNothing], when you want the finder to not find anything.
|
||||
/// * [findsOneWidget], when you want the finder to find exactly one widget.
|
||||
/// * [findsNWidgets], when you want the finder to find a specific number of widgets.
|
||||
/// * [findsAtLeastNWidgets], when you want the finder to find at least a specific number of widgets.
|
||||
const Matcher findsWidgets = _FindsWidgetMatcher(1, null);
|
||||
|
||||
/// Asserts that the [Finder] locates at exactly one widget in the widget tree.
|
||||
@ -67,6 +69,7 @@ const Matcher findsWidgets = _FindsWidgetMatcher(1, null);
|
||||
/// * [findsNothing], when you want the finder to not find anything.
|
||||
/// * [findsWidgets], when you want the finder to find one or more widgets.
|
||||
/// * [findsNWidgets], when you want the finder to find a specific number of widgets.
|
||||
/// * [findsAtLeastNWidgets], when you want the finder to find at least a specific number of widgets.
|
||||
const Matcher findsOneWidget = _FindsWidgetMatcher(1, 1);
|
||||
|
||||
/// Asserts that the [Finder] locates the specified number of widgets in the widget tree.
|
||||
@ -82,8 +85,25 @@ const Matcher findsOneWidget = _FindsWidgetMatcher(1, 1);
|
||||
/// * [findsNothing], when you want the finder to not find anything.
|
||||
/// * [findsWidgets], when you want the finder to find one or more widgets.
|
||||
/// * [findsOneWidget], when you want the finder to find exactly one widget.
|
||||
/// * [findsAtLeastNWidgets], when you want the finder to find at least a specific number of widgets.
|
||||
Matcher findsNWidgets(int n) => _FindsWidgetMatcher(n, n);
|
||||
|
||||
/// Asserts that the [Finder] locates at least a number of widgets in the widget tree.
|
||||
///
|
||||
/// ## Sample code
|
||||
///
|
||||
/// ```dart
|
||||
/// expect(find.text('Save'), findsAtLeastNWidgets(2));
|
||||
/// ```
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [findsNothing], when you want the finder to not find anything.
|
||||
/// * [findsWidgets], when you want the finder to find one or more widgets.
|
||||
/// * [findsOneWidget], when you want the finder to find exactly one widget.
|
||||
/// * [findsNWidgets], when you want the finder to find a specific number of widgets.
|
||||
Matcher findsAtLeastNWidgets(int n) => _FindsWidgetMatcher(n, null);
|
||||
|
||||
/// Asserts that the [Finder] locates a single widget that has at
|
||||
/// least one [Offstage] widget ancestor.
|
||||
///
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user