queries returned by render are not scoped
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả 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
Trước tiên, hãy xem xét cách render trả về các truy vấn của nó và cách within(container) liên kết các truy vấn. Sau đó, tái hiện ví dụ được cung cấp rồi xác minh rằng các truy vấn của render chỉ tìm kiếm trong container được trả về, trong khi screen vẫn có thể tìm kiếm trên toàn bộ tài liệu. Các tác động của breaking-change và bản phát hành cần được giải quyết trước khi triển khai.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
@testing-library/reactversion: 14.1.2- Testing Framework and version: Jest 29.7
- DOM Environment: jsdom 20.0.3
Relevant code or config:
it('uses a consistent scope', () => {
const MyComponent = () => {
useEffect(() => {
const separateElement = document.createElement('div');
separateElement.textContent = 'hello';
document.body.append(separateElement);
return () => separateElement.remove();
}, []);
return (
<div>
<div>hello</div>
</div>
);
};
const { container, getByText } = render(<MyComponent />);
within(container).getByText('hello'); // passes
getByText('hello'); // fails (finds 2 elements)
});
What happened:
The first test (within(container).getByText('hello')) passes, and the second (getByText('hello')) fails:
Found multiple elements with the text: hello
Here are the matching elements:
Ignored nodes: comments, script, style
<div>
hello
</div>
Ignored nodes: comments, script, style
<div>
hello
</div>
Problem description:
The container and queries returned by render should be consistent with each other: the queries should search within the returned container by default, to avoid pollution from other tests and libraries which attach elements to other parts of the DOM. For users who need to check the wider document, they can continue to use screen.
It is also worth noting that the documentation claims that the queries are "bound", which does not match the current behaviour (since they apply globally across the document).
Suggested solution:
It is possible to make a wrapper function in user-space which works around this, which should be easy to integrate into the core library:
export const renderScoped = (ui: ReactElement, options?: RenderOptions) => {
const rendered = render(ui, options);
return {
...rendered,
...within(rendered.container),
};
};
This will be a potentially breaking change for users who currently rely on the queries not being scoped, so probably needs to be a "4.2" release.
- 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của testing-library/react-testing-library
-
fireEvent.select does not wrap its automatic native focus in actCó thể đã có người làm @sergioperezcheco đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict modeCó thể làm lại được @suhailopensource đã nhận 74 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
testing-library/react-testing-library#1466 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
testing-library/react-testing-library#1459 · 2 bình luận ·
-
perf: optimize container lookup with early exitCó thể làm lại được @Ch-Abhinav-Chowdary đã nhận 300 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 35/100
testing-library/react-testing-library#1430 · 1 bình luận ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)Có thể đã có người làm @swarnim02 đã nhận 317 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
Tất cả issue của testing-library/react-testing-library
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
dusk-network/exu#17 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
jspreadsheet/ce#1809 ·
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
githubnext/gh-aw-workshop#4458 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: CartoonitoĐang mởcheck:failed feeds:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
iptv-org/database#37390 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 9 ngày
-
bug: directory index route root priority is overwritten when wildcard is falseCó thể đã có người làm @TalhaHunter101 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
fastify/fastify-static#617 ·