VUE测试utils,在父上下文中测试示波器的插槽逻辑
我有一个“父”组件,其唯一重点是实现一个自定义表组件,称为< vtable>
我想测试特定于父的逻辑,因为它在各种范围的上下文中使用子桌上的老虎机。
这些插槽是根据标题中提供的属性动态声明的。
给定:
const headers = [
{ trackBy: 'lastName', sortable: true, width: '85px' },
{ trackBy: 'status', sortable: true, width: '95px' }
]
实现中阐明以下插槽
<template>
<div class="Foo">
<div class="Foo-table">
<VTable
:headers="headers"
:rows="rows"
:sort="Sort"
:numeration="getNumeration"
:loading="isLoading"
striped
numerated
@sort="onSort"
>
<template v-slot:row.lastName="{ row, index }">
... Custom Implementation ...
</template>
<template v-slot:row.status="{ row, index }">
... Custom Implementation ...
</template>
...
然后,将在我对每个范围内插槽内的特定逻辑感兴趣的
。我可以
const wrapper = shallowMount(
index,
{
localVue,
mocks,
store: new Vuex.Store(store),
stubs: {
'VTable': VTable
}
})
通过以下方式求助于原始输出,
const table = wrapper.findComponent({ name: 'VTable' })
table.vnode.elm.innerHTML
但是任何尝试使用find/findcomponent/etc的尝试。是否从包装器
或表
不成功。有办法这样做吗?我想匹配的RAW HTML是不建议使用的。
I have a "parent" component whose sole focus is to implement a custom table component called <VTable>
I would like to test the logic specific to the parent as it is used in the context of various scoped slots on the child table.
the slots are dynamically declared based on properties supplied in the header.
Given:
const headers = [
{ trackBy: 'lastName', sortable: true, width: '85px' },
{ trackBy: 'status', sortable: true, width: '95px' }
]
then the following slots will be explosed in an implementation
<template>
<div class="Foo">
<div class="Foo-table">
<VTable
:headers="headers"
:rows="rows"
:sort="Sort"
:numeration="getNumeration"
:loading="isLoading"
striped
numerated
@sort="onSort"
>
<template v-slot:row.lastName="{ row, index }">
... Custom Implementation ...
</template>
<template v-slot:row.status="{ row, index }">
... Custom Implementation ...
</template>
...
I am interested in the specific logic within each of the scoped slots.
I can resort to
const wrapper = shallowMount(
index,
{
localVue,
mocks,
store: new Vuex.Store(store),
stubs: {
'VTable': VTable
}
})
and find the raw output via:
const table = wrapper.findComponent({ name: 'VTable' })
table.vnode.elm.innerHTML
but any attempts to use find/findComponent/etc. whether called from wrapper
or table
are unsuccessful. Is there a way to do this? I imagine matching raw html is discouraged.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我实例中,解决方案是将所有其他组件都放置在
vtable
组件上均与示波器插槽。如果未固执的组件较少通用,则此方法带有警告,该方法可能会变得脆弱(这本身可能表明所讨论的组件需要重构)
The solution in my instance was to stub every other component bar the
VTable
component with the scoped slots.This approach carries the caveat that tests could become brittle if the component that wasn't stubbed is less generic (that in itself might be an indicator that the component in question requires refactoring)