Uncaught Error: Module name “lib/chai” has not been loaded yet for context: use require([])

倾然丶 夕夏残阳落幕 提交于 2019-12-13 02:46:58

问题


i m using karma-mocha ..my karma.conf file is working with karma-jasmine...but not working with karma-mocha....my karma.conf file:--

module.exports = function(config){
  config.set({

    basePath : '../app',

    preprocessors: {
      '**/*.html':'ng-html2js'
    },

    ngHtml2JsPreprocessor: {
      prependPrefix: '/'
    },

    files : [
    'node_modules/jquery/**/*.js',
      'lib/angular/angular.js',
      'lib/angular/angular-*.js',
      '../test/lib/angular-mocks.js',
      '../test/lib/sinon-1.15.0.js',
      '../test/chai/chai.js',
      'js/**/*.js',
      '../test/unit/**/*.js',
      '**/*.html'
    ],

    autoWatch : true,

    frameworks: ['mocha','requirejs','chai'],

    browsers : ['Chrome'],

    plugins : [
      'karma-chrome-launcher',
      'karma-mocha',
      'karma-ng-html2js-preprocessor',
      'karma-requirejs',
      'karma-chai'
    ],

    junitReporter : {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
    }

  });
};

回答1:


you are missing chai lib path files array in which is dependency to mocha.include it.

files : [
        'node_modules/jquery/**/*.js',
          'lib/angular/angular.js',
          'lib/angular/angular-*.js',
          '../test/lib/angular-mocks.js',
          '../test/lib/sinon-1.15.0.js',
          '../test/chai/chai.js',
          'js/**/*.js',
          '../test/unit/**/*.js',
          '**/*.html'
        ],



回答2:


I came across a similar situation just with Jasmine. I'd like to introduce my solution.

Try it what is written in the error message. There is a link to a website: http://requirejs.org/docs/errors.html#notloaded

//If this code is not in a define call,
//DO NOT use require('foo'), but use the async
//callback version:
require(['foo'], function (foo) {
    //foo is now loaded.
});

My case written for Jasmine in Coffee script looks like this:

sinon = require(['sinon', 'jasmine-sinon']) (foo)->

Now I can use sinon as an object in my unit test and can also follow the documentation of sinon, as well as jasmin-sinon.



来源:https://stackoverflow.com/questions/36104971/uncaught-error-module-name-lib-chai-has-not-been-loaded-yet-for-context-use

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