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()을 선언해주면 된다.
'개발 > Web Programming' 카테고리의 다른 글
[React Native] xcrun: error: SDK "iphoneos" cannot be located (0) | 2021.12.21 |
---|---|
next.js의 Link 태그내부에 반드시 a태그를 사용해야할까? (0) | 2021.12.15 |
jest에서 localStorage를 mocking하여 test하는법 (0) | 2021.10.06 |
jest에서 MessageChannel등의 window 객체를 못찾는 경우 해결방법 (0) | 2021.10.06 |
jest에서 cypress로 테스트 프레임워크를 바꿔야겠다고 결심했다가 취소한 이유 (0) | 2021.09.20 |