Closed Yimiprod closed 2 months ago
@testing-library/react
const Test = () => { return ( <> <output name="not-found">NOT FOUND</output> <output aria-label="found">IS FOUND</output> </> ); }; describe('not founding status role with standard name attribute', () => { it('should have found both status', () => { const { getByRole } = render(<Test />); const statusOne = getByRole('status', { name: 'not-found' }); // this one will fail const statusTwo = getByRole('status', { name: 'found' }); expect(statusOne).toHaveValue('NOT FOUND'); expect(statusTwo).toHaveValue('IS FOUND'); }); });
Tried to find by role a "status" with <output/> element, with the attribute name on it.
"status"
<output/>
name
It is flagged as an empty name:
Run example code in jest environnement. The one named with aria-label is correctly named, the one with name attribute isn't.
aria-label
The name attribute is a standard for input and output naming, the fact that we have to use aria-label mean that the name is lost in the process.
input
output
*ByRole() for <output/> should find by name for aria-label and name both.
*ByRole()
Hi @Yimiprod. The name attribute is not an accessible name which is what the name property means, it's only a name for development use cases and is not reflected to our users. More on this is available in our docs.
@testing-library/react
version: ^15.0.4Relevant code or config:
What you did:
Tried to find by role a
"status"
with<output/>
element, with the attributename
on it.What happened:
It is flagged as an empty name:
Reproduction:
Run example code in jest environnement. The one named with
aria-label
is correctly named, the one withname
attribute isn't.Problem description:
The
name
attribute is a standard forinput
andoutput
naming, the fact that we have to usearia-label
mean that the name is lost in the process.Suggested solution:
*ByRole()
for<output/>
should find by name foraria-label
andname
both.