【发布时间】:2023-04-10 01:13:05
【问题描述】:
我对 vue js 中的单元测试非常陌生。我刚刚通过这个网站学习单元测试“https://vue-test-utils.vuejs.org/guides/#testing-single-file-components-with-mocha-webpack”。当我在“mocha-webpack”中练习示例时,我得到了这个错误
WEBPACK Failed to compile with 1 error(s)
Error in ./src/Counter.vue
TypeError: Super expression must either be null or a function
at /opt/htdocs/guru/unitTest_prct/node_modules/prettier/index.js:32893:5
at /opt/htdocs/guru/unitTest_prct/node_modules/prettier/index.js:32913:4
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mdbvue@4.2.0 test: `mocha-webpack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mdbvue@4.2.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-09-06T10_28_47_073Z-debug.log
谁能告诉我如何解决这个错误。这是我的 Counter.vue 文件
<template>
<div>
<div>
{{ count }}
<button @click="increment">Increment</button>
</div>
</div>
</template>
<script>
export default {
data () {
return {
count: 0
}
},
methods: {
increment () {
this.count++;
}
}
};
</script>
这是我的 Counter.spec.js 文件
import { shallowMount } from '@vue/test-utils'
import Counter from '../src/docs/Counter.vue'
describe('Counter.vue', () => {
it('increments count when button is clicked', () => {
const wrapper = shallowMount(Counter)
wrapper.find('button').trigger('click')
expect(wrapper.find('div').text()).toMatch('1')
})
})
【问题讨论】:
-
你能发布你的 Counter.vue 文件吗?
-
@yuriy636 我已经更新了我的 counter.vue 文件
-
我们可以看看你的进口吗?
-
@P3trur0 我在这里添加我的 Counter.spec.js 文件
标签: javascript node.js vue.js