Javascript “摩卡-柴业”;“未定义套件”;

Javascript “摩卡-柴业”;“未定义套件”;,javascript,mocha.js,karma-runner,Javascript,Mocha.js,Karma Runner,我是jscript tdd的新手,遇到了一个问题,希望有人能告诉我我正在做什么。 在浏览器中运行测试(通过HTML文件),一切正常。通过节点和业力运行它们,我得到了以下异常 我想在node.js主机中的karma中使用Mocha和Chai。 我通过npm安装[…]安装——保存开发人员摩卡咖啡和卡玛摩卡咖啡 我有一个这样的测试库 suite('first suite', function () { test('SuccessTest', function () { expe

我是jscript tdd的新手,遇到了一个问题,希望有人能告诉我我正在做什么。 在浏览器中运行测试(通过HTML文件),一切正常。通过节点和业力运行它们,我得到了以下异常

我想在node.js主机中的karma中使用Mocha和Chai。 我通过
npm安装[…]安装——保存开发人员
摩卡咖啡卡玛摩卡咖啡

我有一个这样的测试库

suite('first suite', function () {
    test('SuccessTest', function () {
        expect(1).to.equal(1);
    });

    test('FailTest', function () {
        expect(1).to.equal(2);
    });
});
在节点中,我使用karma init创建配置文件,在其中我将框架设置为

frameworks: ['mocha','chai'],
现在当我运行karma时,它得到了这个错误

“未定义套件”

我认为把摩卡咖啡和柴酒作为框架应该有效吗

我还安装了karma mocha和karma chai插件

我做错了什么?我必须做什么

整个karma配置文件

// Karma configuration
// Generated on Mon Sep 23 2013 17:24:19 GMT+0200 (Mitteleuropäische Sommerzeit)

module.exports = function(config) {
  config.set({

    // base path, that will be used to resolve files and exclude
    basePath: '',


    // frameworks to use
    frameworks: ['mocha','chai'],


    // list of files / patterns to load in the browser
    files: [
      'tests.js'
    ],


    // list of files to exclude
    exclude: [

    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['Chrome'],


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};
我还尝试将mocha.js和chai.js添加到文件加载列表中,但没有效果

files: [
  'mocha.js',
  'chai.js',
  'tests.js'

],

当我将测试更改为jasmine时,它会工作。

这是因为Karma没有“chai”框架/插件,但我认为拥有一个框架/插件是个好主意

为了使用“tdd”摩卡风格(默认为bdd),您需要在一些包含的文件中执行此操作:

您需要手动加载“chai”:

module.exports = function(config) {
  config.set({
    files: [
      'path/to/chai.js',
      'config-mocha.js',
      // .. your source and test files
    ]
  });
};

你试过这个吗?我现在试过了。问题是我以“因果报应跑”开始我的环境。我得到了错误。仅在浏览器中运行mocha是可行的。尝试将mocha设置为框架,而不是chai,然后从文件中删除mocha.js[]但保留chai…这只是一个猜测…我创建了两个问题来简化此过程:,谢谢你的回复,我认为这样做就可以了,所以我的假设是错误的?只是想指出,你的解决方案解决了这个问题:-)如果使用gulp,有没有办法作为gulp mocha的额外财产?
module.exports = function(config) {
  config.set({
    files: [
      'path/to/chai.js',
      'config-mocha.js',
      // .. your source and test files
    ]
  });
};