Improve/create documentation for ReactTestUtils.renderIntoDocument()
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 11.8k
- Fork
- 7.9k
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 11
Mô tả
This issue was originally reported by @the-spyke via facebook/react/issues/10330
There is almost none documentation about how to actually use .renderIntoDocument() method. I can't find find answers on those questions on Jest's website or enzyme's (I know that it's not Facebook) either.
- If I render a component into a DOM in a test, how will it be destroyed?
- Should I clean up by myself?
- What tools to use for this?
- Just
.unmountComponentAtNode()? - Where I will get the container to pass in?
- What about additional component trees like in Popovers?
- What are the best ways to test that there aren't any parts left after my component were unmounted?
It will be nice to see such information before people will met memory leaks in their tests, and also help to establish good practices for writing tests.
Additional notes:
- Calling
.renderIntoDocument()returns you an instance - This instance was rendered into freshly created DOM element, which now represents a detached tree
- There's also a reference to the instance in ReactDOM's internal map
- So, even if you remove all your references to this instance, on every call to
.renderIntoDocument()you will get 1 detached tree hanging in memory + 1 instance of a React component with all its props not available for garbage collection
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.
Hướng nghiên cứu
Bắt đầu với tài liệu Test Utils được liên kết cho renderIntoDocument() và xem xét entry point liên quan unmountComponentAtNode(). Ghi lại cách cây DOM bị tách rời và instance của component được dọn dẹp, container đến từ đâu, các cây bổ sung được xử lý như thế nào và các test có thể xác minh việc dọn dẹp ra sao.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, react
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100