반응형
Vue: 동적 컴포넌트 Import 테스트 방법
이 심플한 Vue SFC는 프로펠러 값이 지정된 컴포넌트를 렌더링합니다.
<template>
<component :is="component" v-bind="stepProps" />
</template>
<script>
import { _ } from 'core'
export default {
name: 'SetupFlow',
props: {
type: {
type: String,
required: true
},
step: {
type: String,
required: true
},
stepProps: Object
},
computed: {
component () {
const camelCaseName = _.camelCase(this.step)
const name = camelCaseName.charAt(0).toUpperCase() + camelCaseName.slice(1)
return () => import(`@/components/ProfileSetup/GMB/${name}`)
}
}
}
</script>
테스트에서는 Import된 컴포넌트가 렌더링되고 있는지 확인만 하면 됩니다.지금까지의 테스트 파일은 다음과 같습니다.
import { createLocalVue, shallowMount } from '@vue/test-utils'
import SetupFlow from '@/components/ProfileSetup/SetupFlow'
const localVue = createLocalVue()
describe('SetupFlow.vue', () => {
let propsData
let stubs
beforeEach(() => {
propsData = {
type: 'GMB',
step: 'step-example' // this file does not exist, so I need to mock `import`
}
})
it('renders the given step component', async () => {
const wrapper = shallowMount(SetupFlow, { localVue, propsData })
})
})
에러는 테스트 시 하는 에러입니다.
방법 생각 없어?import
해서step-example
의 vue 컴 환 환 환 、 하? ?? ? ???
언급URL : https://stackoverflow.com/questions/60011303/vue-how-to-test-dynamic-components-import
반응형
'programing' 카테고리의 다른 글
URL이 변경되기 전에 스토어 상태가 업데이트되는 Nuxt.js 문제 (0) | 2022.06.26 |
---|---|
VueJs & Vuetify 프로젝트에서 Vee-Validate 3.x를 실행 (0) | 2022.06.26 |
Vuex를 올바르게 테스트하는 방법 (0) | 2022.06.26 |
도대체 봄콩이란 무엇일까요? (0) | 2022.06.26 |
목록 또는 세트의 첫 번째 요소를 얻는 방법 (0) | 2022.06.26 |