【发布时间】:2020-06-02 06:42:53
【问题描述】:
我正在使用 Vue utils jest 框架来覆盖我的 vue.js。像这样运行其显示的错误。请参考屏幕截图。
我的vue代码如下
<div id="tile" class="tile" data-scale="2.4" @mouseover="cursorEnters" @mouseout="cursorLeaves" @mousemove="cursorMove($event)" :data-image="imageUrl"
>
我的js代码如下
mounted() {
this.initializationImageZoom();
},
initializationImageZoom() {
const tile = document.querySelector('#tile');
tile.innerHTML += '<div id="photo" class="photo"></div>';
tile.children[0].style.backgroundImage = 'url(' + this.imageUrl + ')';
},
在我的测试用例下面
import { shallowMount } from '@vue/test-utils';
const imageUrl = "https://i.ytimg.com/vi/ETsekJKsr3M/maxresdefault.jpg";
let wrapper;
const ImageZoom = require('./ImageZoom.vue').default;
beforeEach(() => {
wrapper = shallowMount(ImageZoom, {
propsData: {
imageUrl,
}
});
});
afterEach(() => {
wrapper.destroy();
});
describe('NoRecords.vue', () => {
it('should have props (imageUrl) type as Object', () => {
expect(typeof wrapper.vm.imageUrl).toBe('string');
});
});
在通过测试用例渲染 vue 组件时。它显示的错误是这样的(参考屏幕截图)
【问题讨论】:
-
@tony19 我已经更新了问题和我的 vue 代码。请参考并帮助我
-
您可以添加您正在为此功能编写的测试用例吗?
-
@NipunJain 我已经更新了我的测试用例。如果我开始渲染会发生此错误。(请参阅屏幕截图)
标签: unit-testing vue.js vuejs2 jestjs testcase