[英]Mocha - Chai Karma “suite is not defined”
I'm quite new to jscript tdd and got a problem, hope someone can show me what I'm doing worng. 我对jscript tdd很新,遇到了问题,希望有人能告诉我我在做什么。 Running the Tests in a browser (via HTML File) everything works fine. 在浏览器中运行测试(通过HTML文件)一切正常。 running them through node and karma i got the following exception 通过节点和业力运行它我得到以下异常
I want to use Mocha and Chai within karma in node.js host. 我想在node.js主机中的karma中使用Mocha和Chai。 I installed via npm install [...] --save-dev
mocha and karma-mocha 我通过npm install [...] --save-dev
mocha和karma-mocha安装
I've a testlibrary like this 我有一个像这样的测试库
suite('first suite', function () {
test('SuccessTest', function () {
expect(1).to.equal(1);
});
test('FailTest', function () {
expect(1).to.equal(2);
});
});
in node i used karma init to create the config file in which i set frameworks to 在节点我使用karma init创建配置文件,我在其中设置框架
frameworks: ['mocha','chai'],
now when I run karma it got this error 现在,当我运行业力时,它得到了这个错误
"suite is not defined" “套房没有定义”
I assumed that declaring mocha and chai as frameworks this should have worked? 我假设将mocha和chai声明为框架应该有效吗?
I also installed in node the karma-mocha and karma-chai plugins. 我还在节点中安装了karma-mocha和karma-chai插件。
What do I wrong and what do I have to do ? 我错了什么,我该怎么办?
where the whole karma config file 整个业力配置文件的位置
// 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
});
};
I also tried to add mocha.js and chai.js to the file load list but this didn't help 我还尝试将mocha.js和chai.js添加到文件加载列表中,但这没有帮助
files: [
'mocha.js',
'chai.js',
'tests.js'
],
When I change tests to jasmine it works. 当我将测试更改为茉莉花时,它可以正常工作。
This is because there is no "chai" framework/plugin for Karma, but I think it's a good idea to have one. 这是因为Karma没有“chai”框架/插件,但我认为拥有一个是一个好主意。
You need to do this in some of your included files, in order to use "tdd" mocha style ("bdd" is the default one): 您需要在一些包含的文件中执行此操作,以便使用“tdd”mocha样式(“bdd”是默认样式):
// in config-mocha.js
window.mocha.setup({ui: 'tdd'});
You need to load "chai" manually: 你需要手动加载“chai”:
module.exports = function(config) {
config.set({
files: [
'path/to/chai.js',
'config-mocha.js',
// .. your source and test files
]
});
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.