【发布时间】:2019-08-07 19:55:35
【问题描述】:
我想在 Test.vue 中测试 testMethod,但是 testMethod 使用了从 App.js 导入的 mixin。
Test.vue
<script>
export default {
methods: {
testMethod() {
return 'get'+this.getTestMixin();
}
},
};
</script>
mixins/common.js
export default {
methods: {
getTestMixin() {
return 'test';
},
},
};
如何模拟 mixin?我试图像下面那样模拟 mixin 但失败了,知道我在哪里做错了吗?
function getTestMixin() {
return 'test';
}
const localVue = createLocalVue()
localVue.mixin(getTestMixin)
const wrapper = shallowMount(Test, {
localVue,
})
错误信息如下:
TypeError: Cannot read property 'props' of undefined
46 | beforeEach(() => {
> 47 | wrapper = shallowMount(Test, {
| ^
48 | localVue,
49 | });
50 | });
【问题讨论】:
标签: unit-testing vue.js