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

th of scope rowgroup is not rowheader

Open
#930 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  • @testing-library/dom version: v7.29.0 ( Use @testing-library/react v11.2.6 )
  • Testing Framework and version: jest v2.26.3
  • DOM Environment: jsdom v16.5.3
Relevant code or config:

table element includes th just like Belgium or The Netherlands rowgroup in https://developer.mozilla.org/en-US/docs/Learn/HTML/Tables/Advanced#tables_for_visually_impaired_users

import React from 'react'

function Counter() {
  return (
    <table>
      <caption>Sample Table</caption>
      <tbody>
      <tr>
        <th scope='rowgroup' rowSpan={3}>Group1</th>
        <th scope='row'>RowHeader1</th>
        <td>Test1</td>
      </tr>
      <tr>
        <th scope='row'>RowHeader2</th>
        <td>Test2</td>
      </tr>
      <tr>
        <th scope='row'>RowHeader3</th>
        <td>Test3</td>
      </tr>
      </tbody>
    </table>
  )
}

export default Counter
import React from 'react'
import {render} from '@testing-library/react'
import Counter from '../'

test('increments the count', () => {
  const {getByRole} = render(<Counter />)

  expect(getByRole('rowheader', { name: 'Group1' })).toBeVisible()
})
What you did:

When using getByRole(..) to get <th scope="rowgroup">..</th>, this element is not rowheader but columnheader.

What happened:
TestingLibraryElementError: Unable to find an accessible element with the role "rowheader" and name "Group1"

Here are the accessible roles:

  table:

  Name "Sample Table":
  <table />

  --------------------------------------------------
  rowgroup:

  Name "":
  <tbody />

  --------------------------------------------------
  row:

  Name "Group1 RowHeader1 Test1":
  <tr />

  Name "RowHeader2 Test2":
  <tr />

  Name "RowHeader3 Test3":
  <tr />

  --------------------------------------------------
  columnheader:

  Name "Group1":
  <th
    rowspan="3"
    scope="rowgroup"
  />

  --------------------------------------------------
  rowheader:

  Name "RowHeader1":
  <th
    scope="row"
  />

  Name "RowHeader2":
  <th
    scope="row"
  />

  Name "RowHeader3":
  <th
    scope="row"
  />

  --------------------------------------------------
  cell:

  Name "Test1":
  <td />

  Name "Test2":
  <td />

  Name "Test3":
  <td />

  --------------------------------------------------

<body>
  <div>
    <table>
      <caption>
        Sample Table
      </caption>
      <tbody>
        <tr>
          <th
            rowspan="3"
            scope="rowgroup"
          >
            Group1
          </th>
          <th
            scope="row"
          >
            RowHeader1
          </th>
          <td>
            Test1
          </td>
        </tr>
        <tr>
          <th
            scope="row"
          >
            RowHeader2
          </th>
          <td>
            Test2
          </td>
        </tr>
        <tr>
          <th
            scope="row"
          >
            RowHeader3
          </th>
          <td>
            Test3
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</body>
...
Reproduction:

I created reproduction code from template.
https://github.com/wasanx25/dom-testing-library-template

As an aside, I want to create reproduction code using Codesandbox, but can not running test because of this issue.
https://github.com/codesandbox/codesandbox-client/issues/513

Problem description:

In Chrome and Firefox browser, accessible name of <th scope='rowgroup>...</th> is rowheader.
However, in testing-library, it is different so I cannot write expected test code.

scope rowgroup th accessibility in Chrome scope rowgroup th accessibility in Firefox
Suggested solution:

I submitted this issue according to bug report, if testing-library should do just like browser, I think it should be.

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 with the getByRole('rowheader') reproduction and compare its result for the th scope="rowgroup" example against the Chrome and Firefox behavior described in the issue. Trace the role-mapping entry point used by getByRole, then add or update coverage so the intended role is verified for this markup.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.