Mocha - Chai Karma “suite is not defined”

匿名 (未验证) 提交于 2019-12-03 07:50:05

问题:

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

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);     }); }); 

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

"suite is not defined"

I assumed that declaring mocha and chai as frameworks this should have worked?

I also installed in node the karma-mocha and karma-chai plugins.

What do I wrong and what do I have to do ?

where the whole karma config file

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.

回答1:

This is because there is no "chai" framework/plugin for Karma, but I think it's a good idea to have one.

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'}); 

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     ]   }); }; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!