개발/NestJS
NestJS Test 실행 시, jest가 module을 못 찾는 경우
8시20분
2021. 9. 24. 08:20
NestJS에서 test 코드를 작성하고, npm test로 유닛 테스트를 진행하였는데 다음과 같이 "Cannot find module 'src/common/typeorm.entity' from 'user/user.entity.ts'"에러가 뜨면서 Failed가 발생하였다.
원인은 package.json에 jest 관련 moduleNameMapper가 빠져있어서 test를 할 때 import의 from의 위치를 프로젝트 디렉토리인 root로 지정되어 발생된 일이었다.
"jest": {
// ...
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
}
위와 같이 package.json의 "jest" 부분에 moduleNameMapper 설정을 src 디렉토리로 설정해주면 된다.
NestJS - Test suite failed to run Cannot find module 'src/article/article.entity' from 'comment/comment.entity.ts'
i need help with nestjs and jest testing. I am new to NestJS and i got stuck on Cannot find module error when i run tests. I am trying to test my service and when i run tests i have received error
stackoverflow.com