最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - chai is not defined in Karma-mocha - Stack Overflow

programmeradmin1浏览0评论

I am running my test cases succesfully using mocha-phantomjs configurations. Now I am running these test using Karma launcher. But I get the issue Chai is not defined.

Here is my configuration file.

 module.exports = function(config) {
  config.set({
    client: {
        mocha: {
            ui: 'tdd'
        }
    },
    basePath: '',
    frameworks: ['mocha'],
    files: [
      'web/js/*.js',
      'test/lib/*.js',
      'node_modules/chai/chai.js'  //added this on suggestion of the answer in stackoverflow
    ],
    exclude: [
    ],
    preprocessors: {
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Firefox'],
    singleRun: false,
  });
};

I have researched on it and found this links,

I am running my test cases succesfully using mocha-phantomjs configurations. Now I am running these test using Karma launcher. But I get the issue Chai is not defined.

Here is my configuration file.

 module.exports = function(config) {
  config.set({
    client: {
        mocha: {
            ui: 'tdd'
        }
    },
    basePath: '',
    frameworks: ['mocha'],
    files: [
      'web/js/*.js',
      'test/lib/*.js',
      'node_modules/chai/chai.js'  //added this on suggestion of the answer in stackoverflow
    ],
    exclude: [
    ],
    preprocessors: {
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Firefox'],
    singleRun: false,
  });
};

I have researched on it and found this links,

Share Improve this question edited May 23, 2017 at 10:33 CommunityBot 11 silver badge asked Jul 25, 2014 at 10:08 ankitrankitr 6,1828 gold badges48 silver badges67 bronze badges 2
  • post your solution as answer. – Thomas Commented Aug 26, 2014 at 10:53
  • @thomas - posted the answer – ankitr Commented Aug 26, 2014 at 11:34
Add a ment  | 

2 Answers 2

Reset to default 5

I installed the karma-chai plugin for chai https://github./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_ponents/chai/chai.js to the files list and it should work. So your config might look like this:

files: [
  'bower_ponents/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/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.

发布评论

评论列表(0)

  1. 暂无评论