Thief of Wealth
article thumbnail

 

    The `document` global was defined when React was initialized, but is not defined anymore. This can happen in a test environment if a component schedules an update from an asynchronous callback, but the test has already finished running. To solve this, you can either unmount the component at the end of your test (and ensure that any asynchronous operations get canceled in `componentWillUnmount`), or you can change the test itself to be asynchronous.

 

jest로 테스트를 작성하던 중에 위와같던 에러를 마주했다.

render를 할때에, document객체가 없다고 하는 것이다.

 

window.open을 사용했을 때에는 버튼을 클릭하면 => window.open is not defined가 떳었는데,

이번엔, useEffect로 처음 시작할때 조건에 맞음녀 window.close하도록해서 그런가보다.

 

window.open is not defined를 해결했을때 처럼,

window.close = jest.fn()을 선언해주면 된다.

profile on loading

Loading...