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
8e14c227
Unverified
Commit
8e14c227
authored
Mar 18, 2019
by
Dan Field
Committed by
GitHub
Mar 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it easier to ensure semantics in widgetTests (#29387)
* Make it easier to ensure semantics
parent
a1bee54f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletion
+35
-1
widget_tester.dart
packages/flutter_test/lib/src/widget_tester.dart
+14
-1
widget_tester_test.dart
packages/flutter_test/test/widget_tester_test.dart
+21
-0
No files found.
packages/flutter_test/lib/src/widget_tester.dart
View file @
8e14c227
...
...
@@ -58,6 +58,11 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
/// is defined by the timeout property,
/// which defaults to [TestWidgetsFlutterBinding.defaultTestTimeout].
///
/// If the `enableSemantics` parameter is set to `true`,
/// [WidgetTester.ensureSemantics] will have been called before the tester is
/// passed to the `callback`, and that handle will automatically be disposed
/// after the callback is finished.
///
/// This function uses the [test] function in the test package to
/// register the given callback as a test. The callback, when run,
/// will be given a new instance of [WidgetTester]. The [find] object
...
...
@@ -84,6 +89,7 @@ void testWidgets(
WidgetTesterCallback
callback
,
{
bool
skip
=
false
,
test_package
.
Timeout
timeout
,
bool
semanticsEnabled
=
false
,
})
{
final
TestWidgetsFlutterBinding
binding
=
TestWidgetsFlutterBinding
.
ensureInitialized
();
final
WidgetTester
tester
=
WidgetTester
.
_
(
binding
);
...
...
@@ -91,10 +97,17 @@ void testWidgets(
test
(
description
,
()
{
SemanticsHandle
semanticsHandle
;
if
(
semanticsEnabled
==
true
)
{
semanticsHandle
=
tester
.
ensureSemantics
();
}
tester
.
_recordNumberOfSemanticsHandles
();
test_package
.
addTearDown
(
binding
.
postTest
);
return
binding
.
runTest
(
()
=>
callback
(
tester
),
()
async
{
await
callback
(
tester
);
semanticsHandle
?.
dispose
();
},
tester
.
_endOfTestVerifications
,
description:
description
??
''
,
);
...
...
packages/flutter_test/test/widget_tester_test.dart
View file @
8e14c227
...
...
@@ -589,6 +589,27 @@ void main() {
semanticsHandle
.
dispose
();
});
testWidgets
(
'Can enable semantics for tests via semanticsEnabled'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Container
(
child:
OutlineButton
(
onPressed:
()
{
},
child:
const
Text
(
'hello'
),
),
),
),
),
);
final
SemanticsNode
node
=
tester
.
getSemantics
(
find
.
text
(
'hello'
));
final
SemanticsData
semantics
=
node
.
getSemanticsData
();
expect
(
semantics
.
label
,
'hello'
);
expect
(
semantics
.
hasAction
(
SemanticsAction
.
tap
),
true
);
expect
(
semantics
.
hasFlag
(
SemanticsFlag
.
isButton
),
true
);
},
semanticsEnabled:
true
);
testWidgets
(
'Returns merged SemanticsData'
,
(
WidgetTester
tester
)
async
{
final
SemanticsHandle
semanticsHandle
=
tester
.
ensureSemantics
();
const
Key
key
=
Key
(
'test'
);
...
...
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