Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a3a9a23e
Unverified
Commit
a3a9a23e
authored
Apr 22, 2022
by
Daniel Cardona Rojas
Committed by
GitHub
Apr 22, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add matcher to find at least a given number of widgets (#102081) (#102342)
parent
6ea4aef8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
matchers.dart
packages/flutter_test/lib/src/matchers.dart
+20
-0
matchers_test.dart
packages/flutter_test/test/matchers_test.dart
+36
-0
No files found.
packages/flutter_test/lib/src/matchers.dart
View file @
a3a9a23e
...
...
@@ -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.
///
...
...
packages/flutter_test/test/matchers_test.dart
View file @
a3a9a23e
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment