반응형
Jest에서 VueJ(Nuxt) 스토어를 테스트하는 방법
VueJs 컴포넌트를 테스트하는 Jest 테스트가 있습니다(특히 Nuxt는 중요하지 않습니다).JSON 오브젝트 스토어를 조롱하려고 합니다.나는 아무리 생각해도 이것을 어떻게 테스트해야 할지 모르겠다.테스트 실행 시 발생하는 오류는 "Cannot read property 'easg_logo' of undefined"입니다.
My Vue 컴포넌트(풋터).비디오)
<template>
<div>
<v-img
:height="easg_logo_height"
:src="$store.state.app.easg_logo.src"
:width="easg_logo_width"
contain
/>
<v-img
:height="oma_logo_height"
:src="$store.state.app.oma_logo.src"
:width="oma_logo_width"
contain
/>
</div>
</template>
<script>
export default {
data(){
easg_logo_width: this.$store.state.app.easg_logo.top.width,
easg_logo_height: this.$store.state.app.easg_logo.top.height,
oma_logo_width: this.$store.state.app.oma_logo.top.width,
oma_logo_width: this.$store.state.app.oma_logo.top.width,
}
}
</script>
내 테스트(footer.test.js)
import {shallowMount, createLocalVue} from '@vue/test-utils'
import Vuex from 'vuex';
import Footer from '@components/layouts/default/footer'
import Vuetify from 'vuetify';
const vuetify = new Vuetify();
const localVue = createLocalVue();
localVue.use(Vuex);
describe("Footer tests", ()=> {
let wrapper;
let store;
let state;
beforeEach(() => {
state= {
app: {
easg_logo:{
src: "~/assets/images/easg.jpg",
text: "EASG",
top:{
height: 72,
width: 82
}
},
oma_logo:{
src: "~/assets/images/oma.jpg",
text: "OMA",
top:{
height: 72,
width: 82
}
}
}
}
store = new Vuex.Store({
modules:{
state
}
})
})
test('store test', ()=> {
wrapper = shallowMount(Footer, {store, localVue, vuetify})
console.log(wrapper)
const a = 'a'
expect(a).toBe('a')
});
});
이 상태란 존재하지 않습니다.state
모듈로 잘못 제공되었습니다.
다음 중 하나여야 합니다.
store = new Vuex.Store({
state
})
언급URL : https://stackoverflow.com/questions/70039360/how-to-test-a-vuejs-nuxt-store-in-jest
반응형
'IT이야기' 카테고리의 다른 글
null 포인터와 void 포인터의 차이점은 무엇입니까? (0) | 2022.06.04 |
---|---|
GCC가 비지 대기 루프를 최적화하지 않도록 하려면 어떻게 해야 합니까? (0) | 2022.06.04 |
Vuex Module Getter에 액세스할 수 없음 - 정의되지 않은 속성 'getters'를 읽을 수 없음" (0) | 2022.06.04 |
Linux에서 PATH_MAX는 어디에 정의되어 있습니까? (0) | 2022.06.04 |
Laravel Echo 500 오류(브로드캐스트/인증) (0) | 2022.06.03 |