FrontEngineer JungBam
jest와 axios 호환 이슈 본문
jest를 이용하여 test코드를 작성하면 axios import 이슈가 발생한다.
axios 깃헙에 jest test관련 이슈를 확인하면 해결방법이 몇가지 명시되어 있는데 해결방법을 해본 결과 버전을 다운하는 것 외에 다른 방법은 문제가 해결되지 않았다.
Updating Axios from 0.27.2 to 1.0.0 breaks Jest tests in a create-react-app app · Issue #5026 · axios/axios
I have several React applications created with a Typescript based create-react-app application (and using react-scripts@5.0.1, which depends on jest@27.4.3). Attempting to upgrade Axios from 0.27.2...
github.com
제시된 해결방안
1. axios 버전 다운그레이드
- npm uninstall axios // 기존에 설치된 axios 제거
- npm install axios@0.27.0
2. 설정을 통한 경로 우회
// jest.config.js module.exports = { // ...기타 설정 moduleNameMapper: { '^axios$': '<rootDir>/path/to/axios-mock.js', }, };
3. 설정을 통한 axios 무시module.exports = { transformIgnorePatterns: ['/node_modules/(?!(axios)/)'], };
4. package.json 파일 설정 변경test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!axios)/\"",
반응형
'개발일지' 카테고리의 다른 글
react-native로 개발하기 :: 클린빌드 (0) | 2023.07.07 |
---|---|
RN 빌드시 에러 :: Error: spawn ./gradlew EACCES (0) | 2023.06.21 |
리팩토링이란?(feat.엘리) (0) | 2023.04.25 |
웹 폰트 최적화하기 (0) | 2023.04.11 |
html 시맨틱 요소로 작성하기(feat. inline요소) (0) | 2023.03.02 |
Comments