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),
);