Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Filter by description on findByLabel for password input tests

Đang mở
#1,156 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, react
Lĩnh vực
frontend, testing-qa

Hướng nghiên cứu

Bắt đầu với các điểm vào truy vấn getByLabelText và findByLabelText, sau đó so sánh hành vi của chúng với việc lọc theo description được mô tả cho getByRole. Kiểm tra cách ví dụ password-input cần được khớp thông qua label của nó và nội dung của aria-describedby. Công việc được xem là hoàn tất khi bộ lọc description được yêu cầu hoạt động với các password inputs có label mà không làm hỏng các truy vấn label hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Is your feature request related to a problem? Please describe.

I am trying to test that the inputs in my form have correct inline validation errors set as aria descriptions. This works great when the input is simply a textbox:

<Label>
  Email
  <input type="text' aria-describedby="emailError" />
</Label>
<div id="emailError">Please enter a valid email address</div>

...

expect(findbyRole('textbox', {
    name: 'Email',
    description: 'Please enter a valid email'
})).toBeInTheDocument();

However, when the input is a password since it has no role I cannot use the description field on getByRole to find the element.

Describe the solution you'd like

This issue recommends using getByLabelText for password inputs, so it would be a lot easier if that query could also search by description.

<Label>
  Password
  <input type="password' aria-describedby="passwordError" />
</Label>
<div id="passwordError">Please enter your password</div>

...

expect(findByLabelText('Password', {
    description: 'Please enter your password'
})).toBeInTheDocument();

Describe alternatives you've considered

Alternatively, if react-testing library could do some magic that means findByRole('password') just works, then that would be a very simple solution and most users probably wouldn't event have to think about it.

For now my tests merely assert that the error exists in the page and ignore the describedby connection.

expect(await screen.findByText('Please enter your new password')).toBeInTheDocument();

Additional context Add any other context or screenshots about the feature
request here.

Ngôn ngữ chính
JavaScript
Star
19.7k
Fork
1.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của testing-library/react-testing-library

Tất cả issue của testing-library/react-testing-library

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.