swsnu / swpp2020-team7

냉장고 파먹기 - 냉장고 속 재료를 기반으로 나만의 레시피를 추천받자! 주변 이웃과 재료 거래는 덤!
https://naengpa.shop/
3 stars 3 forks source link

[Testing] not wrapped in act warning #79

Closed vegeshop closed 3 years ago

vegeshop commented 3 years ago

테스팅 중 다음과 같은 warning이 발생하는 경우가 있습니다.

Warning: An update to ExtractMLFeature 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://fb.me/react-wrap-tests-with-act
        in ExtractMLFeature (at ExtractMLFeature.test.tsx:100)
        in Provider (created by WrapperComponent)
        in WrapperComponent

디버깅해보니

const image = import('../../../public/icons/boy.png');

와 같이 임포트된 image를 호출하는 테스트 케이스에서 위 경고가 나타나는 것이 확인되었습니다.

이 경우 image가 있는 부분을

import { act } from 'react-dom/test-utils';

한 act로 감싸주면 문제가 해결됩니다.