chai is not defined in Karma-mocha

南笙酒味 提交于 2019-12-05 08:24:52

I installed the karma-chai plugin for chai https://github.com/eclifford/karma-chai-jquery/issues/3

Change frameworks to this.

frameworks: ['mocha', 'chai']

and add these dependencies.

npm install karma-chai --save-dev

Now I have solved my problem. Hope this will help you also.

You can install karma-chai and add chai to your frameworks as suggested in the approved answer and it will work, but if you'd prefer another way, you can also list it in your files where dependencies are typically listed. Install chai with bower and add bower_components/chai/chai.js to the files list and it should work. So your config might look like this:

files: [
  'bower_components/chai/chai.js',
  '*.test.js'
],

In your list of files above you had node_modules/chai/chai.js which you said was added based on a suggestion from someone on StackOverflow. It probably didn't work because it wasn't properly ordered before the tests.

In my karma.conf.js file, it points to https://npmjs.org/browse/keyword/karma-adapter for a list of frameworks and oddly enough karma-chai is not included in the list, plus karma-chai seems to have issues with RequireJS.

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