You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: Cannot read property 'parentElement' of null
at ResizeDetector.componentWillUnmount (node_modules/react-resize-detector/lib/components/ResizeDetector.js:105:105)
at callComponentWillUnmountWithTimer (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10194:12)
Why?
(추측) ResponsiveContainer내부적으로 Class Component사용해서 Jest환경에서 잘 돌지 않는 것으로 추정.
위와 같이 적용할경우 target must be an Element에러가 발생할 수 있음.
at IntersectionObserver.observe (node_modules/intersection-observer/intersection-observer.js:217:11)
at src/bpl/Graph/useIntersectionObserver.ts:33:16
IntersectionObserver객체를 mocking해주어야 함.
initStoryshots({test: snapshotWithOptions(story=>({createNodeMock: (element)=>{beforeEach(()=>{// IntersectionObserver isn't available in test environmentconstmockIntersectionObserver=jest.fn();mockIntersectionObserver.mockReturnValue({observe: ()=>null,unobserve: ()=>null,disconnect: ()=>null});window.IntersectionObserver=mockIntersectionObserver;});if(element.type===ResponsiveContainer){returncreateNodeMock()}returnelement},})),});
Desc
recharts 의 ResponsiveContainer를 사용하는 경우 스토리북 스냅샷 테스트에서 아래와 같은 에러 발생
Why?
(추측) ResponsiveContainer내부적으로 Class Component사용해서 Jest환경에서 잘 돌지 않는 것으로 추정.
Solution
createNodeMock
생성ResponsiveContainer
에 대해, createNodeMock사용하도록 설정만약 IntersectionObserver를 사용한다면?
위와 같이 적용할경우
target must be an Element
에러가 발생할 수 있음.IntersectionObserver객체를 mocking해주어야 함.
Ref
The text was updated successfully, but these errors were encountered: