🤍 전 강의 25% 할인 중 🤍

2024년 상반기를 돌아보고 하반기에도 함께 성장해요!
인프런이 준비한 25% 할인 받으러 가기 >>

  • 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

warning 이 뜨는 이유가 뭔지 모르겠어요..

22.09.30 16:44 작성 조회수 277

0

console.error Warning: An update to Type inside a test was not wrapped in act(...).

When testing, code that causes React state updates should be wrapped into act(...):

act(() => {

/* fire events that update state */ });

/* assert on the output */

This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act

at Type (C:\git\inflearn\react-shop-test\src\pages\OrderPage\Type.js:8:17) at div at div at OrderPage at OrderContextProvider (C:\git\inflearn\react-shop-test\src\contexts\OrderContext.js:21:43) at div at App

19 | try {

20 | let response = await axios.get(`http://localhost:5000/${orderType}`); > 21 | setItems(response.data);

| ^

22 | } catch (error) {

23 | setError(true);

24 | }

 

at printWarning (node_modules/react-dom/cjs/react-dom.development.js:86:30)

at error (node_modules/react-dom/cjs/react-dom.development.js:60:7)

at warnIfUpdatesNotWrappedWithActDEV (node_modules/react-dom/cjs/react-dom.development.js:27589:9)

at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:25508:5)

at setItems (node_modules/react-dom/cjs/react-dom.development.js:17527:7

at loadItems (src/pages/OrderPage/Type.js:21:13)

 

안녕하세요 강사님.

react context 강의를 들으면서 테스트를 진행하고 있는데,

이런 warning 이 발생합니다. ㅠㅠ

act라는 wrapper를 감싸주라고 하는데,

강의에서는 이런 경고 문구가 안나오는것 같아서..

제가 잘못한 부분이 있는건지 도움 부탁드립니다..

 

test 자체는 다 success가 뜨는데 발생하는 warning 입니다..!

답변 1

답변을 작성해보세요.

0

안녕하세요!

새 글에 깃허브 저장소 주소랑 같이 다시 올려주시면 직접 봐볼게요!

감사합니다.

채널톡 아이콘