在Karma-mocha中没有定义chai

ank*_*itr 5 javascript unit-testing karma-runner karma-mocha

我正在使用mocha-phantomjs配置成功运行我的测试用例.现在我正在使用Karma启动器运行这些测试.但我得到了这个问题Chai is not defined.

这是我的配置文件.

 module.exports = function(config) {
  config.set({
    client: {
        mocha: {
            ui: 'tdd'
        }
    },
    basePath: '',
    frameworks: ['mocha'],
    files: [
      'web/js/*.js',
      'test/lib/*.js',
      'node_modules/chai/chai.js'  //added this on suggestion of the answer in stackoverflow
    ],
    exclude: [
    ],
    preprocessors: {
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Firefox'],
    singleRun: false,
  });
};
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我研究过它,发现这个链接,

ank*_*itr 5

我为chai https://github.com/eclifford/karma-chai-jquery/issues/3安装了karma-chai插件

将框架更改为此.

frameworks: ['mocha', 'chai']
Run Code Online (Sandbox Code Playgroud)

并添加这些依赖项.

npm install karma-chai --save-dev
Run Code Online (Sandbox Code Playgroud)

现在我已经解决了我的问题.希望这也会对你有所帮助.