在使用vue-cli的单元测试(jest)时,报错:
第一:
Your test suite must contain at least one test.
代码:
test.vue:
<template>
<div class="main-content">
</div>
</template>
<style>
.main-content {
}
</style>
<script src="./test.js"></script>
test.js:
export default {
data() {
return {
};
},
methods: {
judgeEmptyObjectByJSON: function (obj) {
return JSON.stringify(obj) === '{}';
}
}
};
test.spec.js
import Vue from 'vue';
import MyComponent from '../../../src/views/test.vue';
describe('判断对象是否为空的第一种方法:JSON.stringify()', () => {
it('空对象{}', () => {
const obj = {};
const vmComponent = new Vue(MyComponent).$mount();
expect(vmComponent.judgeEmptyObjectByJSON(obj)).toBe(true);
});
it('非空对象', () => {
const vmComponent = new Vue(MyComponent).$mount();
const obj = {firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"};
expect(vmComponent.judgeEmptyObjectByJSON(obj)).toBe(false);
});
});
第二:
但是代码中不涉及报错的函数(之前用过,已删,但是一直报错),错误是从node_modules中报出来的,但是控制台和终端运行都不报错,感觉像是没有及时更新到代码,重新启动试过,但是没有什么用
请问,上述问题应该怎么解决?(因为单元测试感觉用的人比较少,网上的资料很少,所以需要各位大神稍加提点)
这里报错是从test.js 报出来的,按道理来讲单元测试应该是不覆盖这个文件才对,
所以你可以看下你的配置文件和启动命令是否正确,如果还是不明白,请贴图详细说明~