Unit testing $mount()上的Vuejs单元测试组件错误

Unit testing $mount()上的Vuejs单元测试组件错误,unit-testing,vue.js,vuejs2,karma-mocha,Unit Testing,Vue.js,Vuejs2,Karma Mocha,我正试图遵循veujs文档规定的标准模式来装载组件,以便通过生命周期挂钩在不同状态下访问其数据,但是,任何调用$mount()的尝试函数在使用Vue实例扩展组件后触发渲染错误,并立即跳过套件中的断言 从包json执行命令: "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run" 规范文件设置和装载函数调用: describe('component.vue', () => { let Cto

我正试图遵循veujs文档规定的标准模式来装载组件,以便通过生命周期挂钩在不同状态下访问其数据,但是,任何调用$mount()的尝试函数在使用Vue实例扩展组件后触发渲染错误,并立即跳过套件中的断言

从包json执行命令:

"cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"
规范文件设置和装载函数调用:

describe('component.vue', () => {
  let Ctor
  let vm

  beforeEach(() => {
    Ctor = Vue.extend(component)
    vm = new Ctor().$mount()
  })
npm运行单元上的错误跟踪:

ERROR LOG: '[Vue warn]: Error in render function: 
(found in <Root>)'
ERROR LOG: TypeError{stack: 'render@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:77038:32
_render@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:10690:26
updateComponent@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:9239:28
get@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:9550:29
Watcher@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:9533:15
mountComponent@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:9243:28
$mount@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:14333:24
$mount@http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:16382:20
http://localhost:9876/base/specs/component.spec.js?adb355a285fbdae55582a83df658adee4846d0e1:46421:27

提前感谢您的帮助。

您也可以粘贴组件吗?渲染中的错误可能是由于不同的原因造成的,如果组件需要数据或使用了您未传递的特定内容,则会触发错误。是的,谢谢,我发现我在组件中的模板引用了$config,对该行进行注释将删除我在运行测试时遇到的错误。您也可以粘贴组件吗?呈现中的错误可能是由于不同的原因造成的,如果您的组件需要数据或使用了您未传递的特定内容,则会触发错误。是的,谢谢您,我发现组件中的模板引用了$config,对该行进行注释将删除我在运行测试时遇到的错误。
module.exports = function (config) {
  config.set({
    // to run in additional browsers:
    // 1. install corresponding karma launcher
    //    http://karma-runner.github.io/0.13/config/browsers.html
    // 2. add it to the `browsers` array below.
    browsers: ['PhantomJS'],
    frameworks: ['mocha', 'sinon-chai'],
    // chai config
    client: {
      chai: {
        includeStack: true
      }
    },
    reporters: ['spec', 'coverage'],
    files: [
      '../../node_modules/babel-polyfill/dist/polyfill.js',
      'specs/*.js'
    ],
    preprocessors: {
      'specs/*.js': ['webpack', 'sourcemap']
    },
    webpack: webpackConfig,
    webpackMiddleware: {
      noInfo: true,
    },
    coverageReporter: {
      dir: './coverage',
      reporters: [
        { type: 'lcov', subdir: '.' },
        { type: 'text-summary' },
      ]
    },
  });
};