vue.js - 使用 Vuetify v-rating 模块测试组件时,“TypeError:无法读取未定义的属性‘isFilled’”
问题描述
我使用 vuetify 的 v-rating 模块为我的组件编写快照测试,但测试返回错误:“TypeError:无法读取未定义的属性 'isFilled'”。
属性“isFilled”是 vuetify 组件的标志,在组件的插槽中使用,我无法找到修复此错误的决定。
我的组件:
<template>
<v-rating
dense
half-increments
readonly
size="35"
>
<template v-slot:item="props">
<template v-if="props.isFilled">
<v-img :src="fullStar" class="mr-1" />
</template>
<template v-else-if="props.isHalfFilled">
<v-img :src="halfStar" class="mr-1" />
</template>
<template v-else>
<v-img :src="emptyStar" />
</template>
</template>
</v-rating>
</template>
<script>
export default {
name: 'MyRatingComponent',
data() {
return {
fullStar: require('@/assets/full-star.img'),
halfStar: require('@/assets/half-star.img'),
emptyStar: require('@/assets/empty-star.img'),
};
},
};
</script>
我的测试:
import Vue from 'vue';
import Vuetify from 'vuetify';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import MyRatingComponentfrom '../MyRatingComponent';
const localVue = createLocalVue();
describe('MyRatingComponent', () => {
let vuetify;
beforeEach(() => {
vuetify = new Vuetify({});
Vue.use(Vuetify);
});
it('should render correctly', () => {
const wrapper = shallowMount(MyRatingComponent, {
localVue,
vuetify,
});
expect(wrapper).toMatchSnapshot();
});
});
我尝试为测试添加值为“isFilled”的计算属性,但没有帮助。我查看了 vutify 文档和 vue test utils 文档以找到决定,但他们没有写我如何模拟这个属性。
如何在不使用评级更改组件中的代码的情况下解决此问题?
解决方案
推荐阅读
- authentication - 我可以设置 nopcommerce 将特定页面重定向到另一个 dotnet 核心应用程序吗?
- azure - 在 Azure 数据工厂中为按需 HDInsight 操作指定目标 Blob 容器
- python - 反斜杠错误 SyntaxError:扫描字符串文字时 EOL
- click - 如何使用 AppleScript 单击屏幕?
- unity3d - 如何在 Unity 中获取值着色器
- javascript - Javascript:如何使在函数中创建的元素可点击
- excel - excel中VBA框架的“可见”属性没有效果,我做错了什么?
- docker - docker-compose 卷不是挂载目录,只有目录内的文件
- reactjs - 材质 UI 图像渲染延迟
- c++ - Unreal Engine 4.26.1 - 随机化行为树并通过 BP 或 C++ 创建行为树