问题描述
我对jscript tdd很新,遇到了问题,希望有人能告诉我我在做什么。
在浏览器中运行测试(通过HTML文件)一切正常。通过节点和业力运行它我得到了以下异常
I'm quite new to jscript tdd and got a problem, hope someone can show me what I'm doing worng.Running the Tests in a browser (via HTML File) everything works fine. running them through node and karma i got the following exception
我想在node.js主机的karma中使用Mocha和Chai。
我是通过 npm install [...] --save-dev
mocha 和 karma-mocha
I want to use Mocha and Chai within karma in node.js host.I installed via npm install [...] --save-dev
mocha and 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);
});
});
在节点中我用karma init创建配置文件,我在其中设置框架
in node i used karma init to create the config file in which i set frameworks to
frameworks: ['mocha','chai'],
现在当我运行业力时出现此错误
now when I run karma it got this error
套件未定义
我认为将mocha和chai声明为框架应该有效吗?
I assumed that declaring mocha and chai as frameworks this should have worked?
我还在节点中安装了karma-mocha和karma-chai插件。
I also installed in node the karma-mocha and karma-chai plugins.
我错了什么我该怎么做?
What do I wrong and what do I have to do ?
其中整个业力配置文件
// 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添加到文件加载列表中,但这没有' t help
I also tried to add mocha.js and chai.js to the file load list but this didn't help
files: [
'mocha.js',
'chai.js',
'tests.js'
],
当我改变时测试茉莉花是否有效。
When I change tests to jasmine it works.
推荐答案
这是因为没有针对Karma的chai框架/插件,但我认为这是一个好主意。
This is because there is no "chai" framework/plugin for Karma, but I think it's a good idea to have one.
你需要在一些包含的文件中执行此操作,以便使用tddmocha样式(bdd是默认值一个):
You need to do this in some of your included files, in order to use "tdd" mocha style ("bdd" is the default one):
// in config-mocha.js
window.mocha.setup({ui: 'tdd'});
您需要手动加载chai:
You need to load "chai" manually:
module.exports = function(config) {
config.set({
files: [
'path/to/chai.js',
'config-mocha.js',
// .. your source and test files
]
});
};
这篇关于Mocha - Chai Karma“套房未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!