This component must be used inside a <RecoilRoot> component.

준이·2023년 5월 3일
0

에러 발생

Next.js+Typescript 환경에서 Jest를 활용한 유닛테스트 중 아래와 같은 에러가 발생했다.
This component must be used inside a <RecoilRoot> component.

구글에 검색해보면 대부분 최상단 <App/> 컴포넌트를 <RecoilRoot/>로 감싸주면 해결된다는 얘기 뿐이었다.
(당연히 Recoil을 사용할 때 감싸주었기 때문에 내가 원하던 내용이 아니었다.)

해결

테스팅 파일에서 render로 감싼 테스팅하고자 하는 컴포넌트를 <RecoilRoot/>로 감싸준다.

Ex : <RecoilRoot><Home></RecoilRoot>

혼자 헤쳐나가기에 쉽지 않은 테스팅의 세계일 것으로 예상된다..

profile
25% Speciallist

0개의 댓글