Skip to content

Get accessible name from element #1378

@dmurvihill

Description

@dmurvihill

In keeping with Guiding Principle #2, I would like to assert what accessible name will be emitted for an element by screen readers and such. Currently this task, which all users of testing-library should be doing, requires implementing a very complicated algorithm or relying on a third-party dependency like the archived accname package.

Suggested implementation:

getAccessibleName(myElement)

Workaround:

expect(screen.getByRole('button', { name: expectedName })).toBe(myElement);

This gives the correct result, but in the failure case the debugging information is unsatisfactory ("expected x, received null" instead of showing the expected and actual name side-by-side).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions