반응형
Vuejs 프로젝트에서 Jest를 vuetify 및 vuex? 노드 모듈과 함께 사용하고 문제를 vuetify하는 방법
나는 현재 그 안에 Vuex와 Vuetify를 사용하는 Jest와 함께 Vue 프로젝트를 테스트하고 있어.어떤 구성 요소에서 어떤 것을 테스트할 때, 그것은 나에게 다음과 같은 많은 오류를 준다.
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in created hook: "TypeError: Cannot read property 'dispatch' of undefined"
found in
---> <DashboardSlots>
<StatusDashboard>
<Root>
console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884
TypeError: Cannot read property 'dispatch' of undefined
at VueComponent.mappedAction (D:\Users\ftg\git\DVBIP_GATEWAY_9\usr\nonius\webadmin\node_modules\vuex\dist\vuex.common.js:1052:34)
at VueComponent.created (D:\Users\ftg\git\DVBIP_GATEWAY_9\usr\nonius\webadmin\src\components\DashboardSlots.vue:197:1)
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Unknown custom element: <v-card> - did you register the component correctly? For recursive components, make
sure to provide the "name" option.
found in
---> <DashboardSlots>
<StatusDashboard>
<Root>
그리고 이것들의 훨씬 더!나는 왜 이런 일이 일어나는지 모르겠다.
이것은 내 jest.config.js 파일이다.
module.exports = {
verbose: true,
roots: ["<rootDir>/src/", "<rootDir>/test/"],
moduleFileExtensions: ['js', 'vue'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
transform: {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest",
},
snapshotSerializers: [
"<rootDir>/node_modules/jest-serializer-vue"
]
}
내 babel.config.js 파일:
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
그리고 이건 간단한 시험이야.
import Component from '@/components/StatusDashboard.vue';
import { mount , createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Vuetify from 'vuetify';
import Actions from '@/vuex/actions.js'
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.use(Vuetify, {});
localVue.use(Vuex)
describe('Component test', () => {
it('check test', () => {
const wrapper = mount(Component)
const test = wrapper.vm.items
console.log(test);
})
})
노드 모듈을 제거하고 다시 설치했지만 해결되지 않았다.
설정하셨습니다.localVue
에 전달하지 않으셨습니다.mount()
옵션으로
다음과 같아야 한다.
mount(Component, { localVue })
//or
shallowMount(Component, { localVue })
반응형
'IT이야기' 카테고리의 다른 글
PROPESS로 HTML 버튼 이름 속성을 전달하는 Vue js (0) | 2022.05.06 |
---|---|
Vue-cli 3 환경 변수 모두 정의되지 않음 (0) | 2022.05.06 |
Vue.js: 프로그래밍 방식으로 기능 구성 요소 인스턴스화 (0) | 2022.05.06 |
Intellij IDEA의 System.out.println() 바로 가기 (0) | 2022.05.06 |
ANSI C와 K&R C의 주요 차이점은 무엇인가? (0) | 2022.05.05 |