Intial props not working when rendering a hook (or I've done something wrong.)
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
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- testing
Hướng nghiên cứu
Bắt đầu với lệnh gọi renderHook và wrapper trong reproduction được cung cấp, sau đó kiểm tra cách initialProps được truyền cho wrapper. Chạy lại kiểm thử custom-step và xác nhận rằng ban đầu wrapper nhận step 2, nhận step 8 sau rerender, đồng thời các assertion của count đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
"@testing-library/dom": "^8.13.0",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "13.3.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer: 18.1.0)"
"`node` version: 18"
"`pnpm` (or `yarn`) version: 7"
Relevant code or config:
In the Reproduction details.
Taking the example from the docs, logged the initial props;
const CounterStepContext = createContext(1);
export const CounterStepProvider = ({
step,
children,
}: {
step: number;
children: React.ReactNode;
}) => {
console.log({ step });
return (
<CounterStepContext.Provider value={step}>
{children}
</CounterStepContext.Provider>
);
};
export function useCounter(initialValue = 0) {
const [count, setCount] = useState(initialValue);
const step = useContext(CounterStepContext);
const increment = useCallback(() => setCount((x) => x + step), [step]);
const reset = useCallback(() => setCount(initialValue), [initialValue]);
return { count, increment, reset };
}
test("should use custom step when incrementing", () => {
const wrapper = ({
children,
step,
}: {
step: number;
children: React.ReactNode;
}) => <CounterStepProvider step={step}>{children}</CounterStepProvider>;
const { result, rerender } = renderHook(() => useCounter(), {
wrapper,
initialProps: {
step: 2,
},
});
act(() => {
result.current.increment();
});
expect(result.current.count).toBe(2);
/**
* Change the step value
*/
rerender({ step: 8 });
act(() => {
result.current.increment();
});
expect(result.current.count).toBe(10);
});
console.log
{ step: undefined }
What you did:
Trying to use initialProps with the renderHook
What happened:
Initial props are not being passed.
No obvious error message, component just isn't receiving the props.
Reproduction:
Problem description:
Suggested solution:
- 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 2 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 72 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 298 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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
processing/p5.sound.js#123 ·
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
PhilflowIO/dav-mcp#146 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add a light/dark theme toggleĐang mởgood first issue hacktoberfest
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Tanishq964/trail-kit.#4 ·
-
Request: <brand-name>Đang mởnew icon permissions in review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
simple-icons/simple-icons#15067 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
mastra-ai/mastra#26562 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày