Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow matchesSemantics to only match certain properties #107859

Closed
@bryanoltman

Description

@bryanoltman

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

Labels

P1High-priority issues at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)a: tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions