我刚刚开始通过 Jest 为我已经存在的Vue.js
项目编写测试用例。
唯一有效的测试用例是Hello World,它只检查是否正在渲染数据。
这是一个自定义规范,似乎无效。
我已经创建了一个 FancyHeading.spec.js 文件
import { shallowMount } from '@vue/test-utils'
import FancyHeading from '@/components/FancyHeading'
describe('FancyHeading', () => {
test('if logged in is false, do not show logout button', () => {
const wrapper = shallowMount(FancyHeading)
expect(wrapper.find('button').isVisible()).toBe(false)
})
test('if logged in, show logout button', () => {
expect(true).toBe(true)
expect(1 + 1).toBe(2)
})
})
对于以下组件:
<template>
<div>
<button class="btn" v-show="loggedIn">Logout</button>
</div>
</template>
<script>
export default {
name: 'fancy-heading',
data () {
return {
loggedIn: false
}
}
}
</script>
由于以下原因,测试用例无法运行:
FAIL tests/unit/FancyHeading.spec.js
● Test suite failed to run
TypeError: Falsy value found in plugins
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:15
at Array.map (<anonymous>)
at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:162:20)
at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:239:36)
at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:373:12)
at File.initOptions (node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at compileBabel (node_modules/vue-jest/lib/compilers/babel-compiler.js:23:21)
at processScript (node_modules/vue-jest/lib/process.js:30:10)
我在这里想念什么?