Javascript 单元测试包含带插槽的Vuetify数据表的Vue组件
我试图用嵌套的Javascript 单元测试包含带插槽的Vuetify数据表的Vue组件,javascript,vue.js,ecmascript-6,jestjs,vuetify.js,Javascript,Vue.js,Ecmascript 6,Jestjs,Vuetify.js,我试图用嵌套的v-data-table组件对一个简单组件进行单元测试。页面在浏览器中正确呈现,但我似乎无法编写一个有效的Jest测试 问题似乎在于我用于插槽的模板——我直接从文档中提取了该模板 当我用v-slot属性注释掉模板时,测试执行得很好 People.vue: <template> <v-data-table :headers="headers" :items="people" disable-pagination disable-s
v-data-table
组件对一个简单组件进行单元测试。页面在浏览器中正确呈现,但我似乎无法编写一个有效的Jest测试
问题似乎在于我用于插槽的模板——我直接从文档中提取了该模板
当我用v-slot
属性注释掉模板时,测试执行得很好
People.vue:
<template>
<v-data-table
:headers="headers"
:items="people"
disable-pagination
disable-sort
disable-filtering
hide-default-footer
:loading="!people"
>
<template v-slot:item.id="{ item }">
<v-icon>
mdi-link-variant
</v-icon>
<router-link
:to="{ name: 'assignments', query: { assignee_id: item.id } }"
>Link</router-link
>
</template>
</v-data-table>
</template>
<script>
export default {
name: "People",
data: () => ({
headers: [
{
text: "Name",
value: "first_name"
},
{
text: "Assignment link",
value: "id"
}
]
}),
props: {
people: {
type: Array,
required: true
}
}
};
</script>
错误消息:
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in render: "TypeError: Cannot read property 'item' of undefined"
found in
---> <VDataTable>
<People>
<Root>
console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884
TypeError: Cannot read property 'item' of undefined
console.error节点_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]:呈现错误:“TypeError:无法读取未定义的属性'item'”
发现于
--->
console.error节点_modules/vue/dist/vue.runtime.common.dev.js:1884
TypeError:无法读取未定义的属性“item”
我遇到了同样的问题,发现如果将v-data-table
包装在div
中,测试成功。由于某种原因,当v-data-table
是模板的根元素时,shallowMount
在玩笑中失败。您是否找到了解决方案?有完全相同的问题。你找到解决办法了吗?没有。Vuetify Discord有人建议在shallowMount
上使用mount
,我认为这样做没有用。请参阅Ryan King bellow的回答。这对我很有效。将v-data-table包装在div中对我起了作用。应标记为正确答案。
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in render: "TypeError: Cannot read property 'item' of undefined"
found in
---> <VDataTable>
<People>
<Root>
console.error node_modules/vue/dist/vue.runtime.common.dev.js:1884
TypeError: Cannot read property 'item' of undefined