testing-library / testing-library/dom-testing-library

expose more functions from role-helpers

Open
#1,356 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

Describe the feature you'd like:

Expose all the computeAriaXXX functions from role-helpers to provide greater flexibility for test authoring. This would enable writing tests like this:

const optionsList = within(getByRole(document.body, 'listbox', { name: /Options list/ }));

expect(
    optionsList.queryAllByRole('option').map(e => ({
        name: computeAccessibleName(e),
        selected: computeAriaSelected(e),
    }))
).toEqual([
    {  name: 'manager1', selected: true },
    {  name: 'external2', selected: false },
]);

Here, we combine the verification of the order and the specific ARIA properties for each option into a single expectation. Otherwise, it would require at least two steps to achieve the same result.

expect(optionsList.queryAllByRole('option').map(e => computeAccessibleName(e))).toEqual(['manager1', 'external2']);
expect(optionsList.queryByRole('option', { name: 'manager1', selected: true })).toBeDefined();
expect(optionsList.queryByRole('option', { name: 'external2', selected: false })).toBeDefined();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the role-helpers module and its public exports, then inspect how the existing computeAccessibleName helper is exposed and tested. Expose the computeAriaXXX functions requested by the issue, and confirm they can be imported for assertions like the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.