-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)Accessibility, e.g. VoiceOver or TalkBack. (aka a11y)a: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Description
Use case
When writing a widget test that verifies the semantic properties of an element, I'm forced to specify every semantics trait the corresponding SemanticsNode has. For example, if I simply want to verify that the element found by find.text('myButton') is seen as a button in the semantics tree, I have to write:
expect(
tester.getSemantics(find.text('myButton')),
matchesSemantics(
label: 'myButton',
isButton: true,
hasTapAction: true,
textDirection: TextDirection.ltr,
isEnabled: true,
isFocusable: true,
hasEnabledState: true,
),
);This is inconvenient for the developer, makes the purpose of the test less clear, and makes the test more brittle, as changes to other semantic values that are irrelevant to this test will cause this test to start failing.
Proposal
Introduce a matcher that only checks the values provided to the matcher. For example, if we were to call such a matcher hasSemantics, the test above could be written as:
expect(
tester.getSemantics(find.text('myButton')),
hasSemantics(isButton: true),
);Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)Accessibility, e.g. VoiceOver or TalkBack. (aka a11y)a: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.