How to wrap a hook with a Provider with prop passing?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, react
Hướng nghiên cứu
Bắt đầu với ví dụ được tham chiếu src/tests/useContext.test.tsx và so sánh hành vi của wrapper và initialProps với thiết lập React 18 của issue. Xác nhận với các maintainer về pattern bọc provider được khuyến nghị, sau đó cập nhật các test hoặc tài liệu liên quan để hành vi truyền prop được mong đợi là rõ ràng và được bao phủ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What is your question:
I have seen the following which was helpful: https://github.com/testing-library/react-hooks-testing-library/issues/23
This question steams further from that with regards to passing initialProps.
I have updated React and DOM ("react": "18.2.0", "react-dom": "18.2.0",) and the React Testing Library ("@testing-library/react": "14.0.0",) to the most recent versions. I have followed that pattern, but notice that the props passed into Provider are only available via children. Please see the example below (borrowed from the tests within the library https://github.com/testing-library/react-hooks-testing-library/blob/1e01273374af4e48a0feb1f2233bf6c76d742167/src/__tests__/useContext.test.tsx):
test('should update value in context when props are updated', () => {
const TestContext = createContext('foo');
const wrapper = ({
current,
children,
}: {
current: string;
children: any;
}) => {
console.log({ current });
console.log({ children });
console.log('nested', children.props.renderCallbackProps);
return (
<TestContext.Provider value={current}>{children}</TestContext.Provider>
);
};
const { result, rerender } = renderHook(() => useContext(TestContext), {
wrapper,
initialProps: {
current: 'bar',
},
});
rerender({ current: 'baz' });
expect(result.current).toBe('baz');
});
// console.logs
console.log
{ current: undefined }
console.log
{
children: {
'$$typeof': Symbol(react.element),
type: [Function: TestComponent],
key: null,
ref: null,
props: { renderCallbackProps: [Object] },
_owner: null,
_store: {}
}
}
console.log
nested { current: 'baz' }
Was this the intended change? Are we supposed to only pass children to a wrapper and then desconstruct those props from it? Can we update the tests or docs to represent the recommended pattern?
- 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 3 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 73 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 299 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 316 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ự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
capricorn86/happy-dom#2485 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 74/100
siyuan-note/siyuan#20429 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
yjh051108/dsh-routing-suite#216 ·
-
[Bug] Completion info popup (.cm-completionInfo) ignores the configured editor fontCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug user-priority/P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
t8y2/dbx#11718 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày