[英]Mocha - Chai Karma “suite is not defined”
我對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'],
現在,當我運行業力時,它得到了這個錯誤
“套房沒有定義”
我假設將mocha和chai聲明為框架應該有效嗎?
我還在節點中安裝了karma-mocha和karma-chai插件。
我錯了什么,我該怎么辦?
整個業力配置文件的位置
// 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'
],
當我將測試更改為茉莉花時,它可以正常工作。
這是因為Karma沒有“chai”框架/插件,但我認為擁有一個是一個好主意。
您需要在一些包含的文件中執行此操作,以便使用“tdd”mocha樣式(“bdd”是默認樣式):
// in config-mocha.js
window.mocha.setup({ui: 'tdd'});
你需要手動加載“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.