【发布时间】:2013-09-23 15:35:17
【问题描述】:
我对 jscript tdd 很陌生并且遇到了问题,希望有人能告诉我我在做什么。 在浏览器中运行测试(通过 HTML 文件)一切正常。通过节点和业力运行它们我得到了以下异常
我想在 node.js 主机的 karma 中使用 Mocha 和 Chai。
我通过npm install [...] --save-dev mocha 和 karma-mocha
我有一个这样的测试库
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 时出现此错误
“套件未定义”
我认为将 mocha 和 chai 声明为框架应该可行?
我还在 node 中安装了 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 时,它可以工作。
【问题讨论】:
-
我现在试过了。问题是我从“业力运行”开始我的环境。我得到了错误。仅在浏览器中运行 mocha 有效。
-
尝试将 mocha 设置为框架,而不是 chai,然后将 mocha.js 从您的 Files[] 中取出,但将 chai 留在...这只是一个猜测...
标签: javascript mocha.js karma-runner