Always test semantics (#35110)
Default `semanticsEnabled` to true for `testWidgets` and fix associated bugs
This commit is contained in:
@@ -71,7 +71,7 @@ typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
|
||||
/// If the `semanticsEnabled` 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.
|
||||
/// after the callback is finished. It defaults to true.
|
||||
///
|
||||
/// This function uses the [test] function in the test package to
|
||||
/// register the given callback as a test. The callback, when run,
|
||||
@@ -100,7 +100,7 @@ void testWidgets(
|
||||
bool skip = false,
|
||||
test_package.Timeout timeout,
|
||||
Duration initialTimeout,
|
||||
bool semanticsEnabled = false,
|
||||
bool semanticsEnabled = true,
|
||||
}) {
|
||||
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
final WidgetTester tester = WidgetTester._(binding);
|
||||
@@ -115,6 +115,7 @@ void testWidgets(
|
||||
test_package.addTearDown(binding.postTest);
|
||||
return binding.runTest(
|
||||
() async {
|
||||
debugResetSemanticsIdCounter();
|
||||
await callback(tester);
|
||||
semanticsHandle?.dispose();
|
||||
},
|
||||
|
||||
@@ -123,7 +123,7 @@ void main() {
|
||||
final Evaluation result = await textContrastGuideline.evaluate(tester);
|
||||
expect(result.passed, false);
|
||||
expect(result.reason,
|
||||
'SemanticsNode#21(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), label: "this is a test",'
|
||||
'SemanticsNode#3(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), label: "this is a test",'
|
||||
' textDirection: ltr):\nExpected contrast ratio of at least '
|
||||
'4.5 but found 1.17 for a font size of 14.0. The '
|
||||
'computed light color was: Color(0xfffafafa), The computed dark color was:'
|
||||
@@ -256,7 +256,7 @@ void main() {
|
||||
final Evaluation result = await androidTapTargetGuideline.evaluate(tester);
|
||||
expect(result.passed, false);
|
||||
expect(result.reason,
|
||||
'SemanticsNode#41(Rect.fromLTRB(376.0, 276.5, 424.0, 323.5), actions: [tap]): expected tap '
|
||||
'SemanticsNode#3(Rect.fromLTRB(376.0, 276.5, 424.0, 323.5), actions: [tap]): expected tap '
|
||||
'target size of at least Size(48.0, 48.0), but found Size(48.0, 47.0)\n'
|
||||
'See also: https://support.google.com/accessibility/android/answer/7101858?hl=en');
|
||||
handle.dispose();
|
||||
|
||||
@@ -33,7 +33,7 @@ void main() {
|
||||
group('semantics', () {
|
||||
testWidgets('Throws StateError if semantics are not enabled', (WidgetTester tester) async {
|
||||
expect(() => find.bySemanticsLabel('Add'), throwsStateError);
|
||||
});
|
||||
}, semanticsEnabled: false);
|
||||
|
||||
testWidgets('finds Semantically labeled widgets', (WidgetTester tester) async {
|
||||
final SemanticsHandle semanticsHandle = tester.ensureSemantics();
|
||||
|
||||
@@ -542,7 +542,7 @@ void main() {
|
||||
|
||||
expect(() => tester.getSemantics(find.text('hello')),
|
||||
throwsA(isInstanceOf<StateError>()));
|
||||
});
|
||||
}, semanticsEnabled: false);
|
||||
|
||||
testWidgets('throws when there are multiple results from the finder', (WidgetTester tester) async {
|
||||
final SemanticsHandle semanticsHandle = tester.ensureSemantics();
|
||||
|
||||
Reference in New Issue
Block a user