You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constMyPassword=()=>{return<label>Hello<inputtype="password"/></label>}constMyPassword2=()=>{return<><labelhtmlFor="password">Hello</label><inputtype="password"id="password"/></>}constMyPassword3=()=>{return<><labelid="label">Hello</label><inputtype="password"aria-labelledby='label'/></>}describe('</>',()=>{it("Passwords are selectedable label 1",()=>{render(<MyPassword/>)expect(screen.getByRole("textbox",{name: /hello/i})).toBeInTheDocument();});it("Passwords are selectedable label 2",()=>{render(<MyPassword2/>)expect(screen.getByRole("textbox",{name: /hello/i})).toBeInTheDocument();});it("Passwords are selectedable label 3",()=>{render(<MyPassword3/>)expect(screen.getByRole("textbox",{name: /hello/i})).toBeInTheDocument();});});
What you did:
Try to write tests to assert that password fields exist.
What happened:
These tests fail.
TestingLibraryElementError: Unable to find an accessible element with the role "textbox" and name `/hello/i`
There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole
Ignored nodes: comments, <script />, <style />
<body>
<div>
<label
id="label"
>
Hello
</label>
<input
aria-labelledby="label"
type="password"
/>
</div>
</body>
35 | render(<MyPassword3 />)
36 |
> 37 | expect(screen.getByRole("textbox", {
| ^
38 | name: /hello/i
39 | })).toBeInTheDocument();
40 | });
This should be added to the examples in the docs. Many of the examples use a "username" input, but there is no mention of "password" near any of them.
type=password having no role is a surprise for many users (as indicated by the many issues in this repo) so I think it would be very valuable to provide guidance from veterans/authors as to which query tool fits the philosophy best for this awkward situation that new users are likely to encounter.
Note, I think I answered my own answer. But can someone clarify - when searching for password fields - should I just search by labelText?
This is possibly a regression of #737 ?
Relevant code or config:
What you did:
Try to write tests to assert that password fields exist.
What happened:
These tests fail.
Reproduction:
Full repro here.
https://github.com/dwjohnston/rtl-password
Run
yarn && yarn test
Problem description:
<input type='password'>
should have role 'textbox'Whoops, no it shouldn't - as per the W3 aria spec - it has no role.
Suggested solution:
The text was updated successfully, but these errors were encountered: