Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Implementation of byRole queries is incorrect. #349

@aaron-nance

Description

@aaron-nance

According to the Testing Library documentation, the byRole queries should return elements based on their default role.

For example, if I my DOM has header tags (h1,h2, etc), queryAllByRole(container, 'header'), should return all the header elements in the container, but instead always returns an empty array. I have tried to get this work with several different tags and their default roles and all have failed.

For example, if I run the following in Jest I get the expected results:

const articleCount = await rendered.queryAllByRole('article'); console.log( `article count = ${articleCount.length}`) 

But the equivalent in Playwright using this library, the returned array is always empty:

const root = await page.locator(ROOT_SEL); const itemArticles = await queryAllByRole(root, 'article'); console.log( `items articles length = ${itemArticles.length}`); 

The byRole queries should be using the accessibility tree to determine roles, but they appear to just be using the "role" attribute on a tag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions