「feat: Add `renderHook` by eps1lon · Pull Request #991 · testing-library/react-testing-library · GitHub」
What: Imlement minimal renderHook from @testing-library/react-hooks Why: @testing-library/react-hooks is not compatible with React 18 and it's questionable if certain APIs will make sense in React 18. This ensures that the supported version of React that is used with your Testing Library APIs is always consistent. error testing: We don't have this solved in @testing-library/react. It should be solved in the renderer testing library. suspense: Can be solved with wrapper waitForNextUpdate: Use waitFor instead. When an update is triggered and what is part of an update is not always clear and in 99% of the cases (even if hooks relying on data e.g. apollo-client) not relevant. See eps1lon/apollo-client#1 How: Implement minimal renderHook with just rerender, rerender and unmount. Assertions are made on the committed result not the render result. Renders are not something to test for since they're ultimately not detereministic depending on the component implementation. However, we don't want to test component implementation details. For more granular testing one could always create a custom test component around the hook under test and pass it to our render. This has always been the recommended approach anyway. But it requires more writing and instead of insisting that this is bad practice we meet devs halfway, provide a render wrapper around creating a test component but then reduce the API of that render wrapper. If your goal was to count renders then React.Profiler is the better approach anyway. Checklist: Documentation added to the docs site: testing-library/testing-library-docs#967 Tests TypeScript definitions updated Ready to be merged
コンテンツ文字数:0 文字
見出し数(H2/H3タグ):0 個
閲覧数:104 件
2022-04-18 11:08:08