반응형
🍟 lottie 오류1
lottie를 사용할 경우 아래와 같은 오류가 발생하였다. 보통 외부라이브러리에서 발생하는데,
아래오 같이 발생할 경우 jest.config.js에서 "transformIgnorePatterns" 에 vue-lottie를 추가해준다.
jest.config.js
/* vue-lottie 추가 */
module.exports = {
transformIgnorePatterns: ['<rootDir>/node_modules/(?!(particles-bg-vue)|(?!@scu/vue)|(?!(vue-lottie))/)'],
}
🥗 lottie 오류2
lottie오류1을 해결했음에도 불구하고, HTMLCanvasElemnt관련한 오류가 발생하였다.
그래서 "jest-canvas-mock"을 추가하였다.
https://www.npmjs.com/package/jest-canvas-mock
jest-canvas-mock
Mock a canvas in your jest tests.. Latest version: 2.5.2, last published: 6 months ago. Start using jest-canvas-mock in your project by running `npm i jest-canvas-mock`. There are 200 other projects in the npm registry using jest-canvas-mock.
www.npmjs.com
그리고, jest.config.js에서 setUpFiles에 추가하였다.
module.exports = {
setupFiles: ["jest-canvas-mock"]
}
🫔 $route 오류
테스트코드 작성시 $route관련하여, undefined 오류가 발생하였다.
이러한 경우는 shallMount에서 $route를 모킹 처리가 필요하다.
shallMount에서 $route에 name프로퍼티를 추가한다.
import LottieComp from '@/components/lottie/LottieComp.vue'
import { shallowMount } from '@vue/test-utils';
describe('', () => {
test('should ', async () => {
shallowMount(LottieComp, {
mocks: {
$route: {
/* name 프로퍼티 추가 */
name: 'go'
}
}
})
});
});
반응형
'테스트코드' 카테고리의 다른 글
🍟 jest 에서 setTimeOut,setInterVal을 사용하기 (0) | 2024.02.27 |
---|---|
🌮 부모컴퍼넌트에 Video 태그가 있는 경우의 단위테스트 (0) | 2024.01.22 |
🥑 jest 에서 만난 문제 (1) | 2023.10.15 |
🎫 jest mock 함수 사용법 정리 (0) | 2023.09.17 |
🍋 테스트 코드 커버리지 - 진행중 (0) | 2023.09.13 |
댓글