首页 > 解决方案 > TypeError: Falsy value found in plugins - Vue Unit Testing with Jest

问题描述

我刚刚开始通过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)

我在这里想念什么?

标签: javascriptunit-testingvue.jstestingjestjs

解决方案


推荐阅读