-
Notifications
You must be signed in to change notification settings - Fork 468
Closed
Labels
jsdomIssue with JSDOM environmentIssue with JSDOM environment
Description
Environment
@testing-library/domversion: 7.22.1jestversion: 22.4.4jest-environment-jsdomversion: 22.4.3yarnversion: 1.22.4nodeversion: 10.15.3
Relevant code or config:
export const App = () => (
<div>
<label for="password">Password</label>
<input id="password" type="password" />
</div>
);import "@testing-library/jest-dom/extend-expect";
import React from "react";
import { render } from "@testing-library/react";
import { App } from "../index";
test("React Testing Library works!", () => {
const { getByRole } = render(<App />);
const passwordField = getByRole("textbox");
expect(passwordField).toBeInTheDocument();
});What you did:
I tried to get a password input using getByRole("textbox"). I've also tried getByLabelText("Password").
What happened:
No element is found, and an error message such as Unable to find an element with the role "textbox" is shown.
Reproduction:
https://codesandbox.io/s/react-testing-library-getbyrole-password-issue-roy0l
Problem description:
It makes it difficult to test a login form without falling back to query selectors or test IDs, something that the library guidelines say should only be used if there is no other choice.
Suggested solution:
Either allow password fields to be found using getByRole("textbox") or support another role if appropriate.
Supporting password fields in getByLabelText would also solve the problem for me.
mstmustisnt
Metadata
Metadata
Assignees
Labels
jsdomIssue with JSDOM environmentIssue with JSDOM environment