2016-03-19 30 views
1

即时使用karma-mocha ..my karma.conf文件与karma-jasmine一起工作...但不与卡玛 - 摩卡工作....我karma.conf文件: -未捕获的错误:模块名称“lib/chai”尚未加载上下文:use require([])

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

    }); 
}; 
+0

控制台上的任何错误? –

+0

@RIYAJ KHAN一切都与茉莉花很好..我不这么认为。 –

回答

0

你缺少chai lib路径中files array是依赖于mocha.include它。

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' 
     ], 
+0

@ RIYAJ KHAN JI仍然会出现同样的错误..... Chrome 49.0.2623(Windows 7 0.0.0)错误 未捕获错误:模块名称“chai”尚未加载上下文:_。使用 需要([]) http://requirejs.org/docs/errors.html#notloaded at C:/ 6-angularjs-fundamentals -m6-testing-exercise-files/Finished/DemoApp/node _modules/requirejs/require.js:143 –

+0

请分享测试脚本 –

+0

这是一个SCRIPT模块; '严格使用'; var chai = require('chai'); expect = chai.expect; chai.should(); 描述( 'calendarHelper',函数(){ beforeEach(模块( 'eventsApp')); 它('赋予0时应该返回1月份,注入(函数(calendarHelper){ 预期(calendarHelper .getMonthName(0)).Be('January'); })) }); –

-1

我刚刚遇到了与茉莉花类似的情况。 我想介绍一下我的解决方案。

试试看错误信息中写的是什么。有一个链接到一个网站: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. 
}); 

我来说,我茉莉花茶脚本编写如下:

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

现在我可以在我的单元测试使用兴农作为一个对象,也可以遵循sinon和jasmin-sinon的文档。

+0

带有一个依赖关系的'require'调用的返回值是**不是一个模块,所以行'sinon = require ([...])'不可能是正确的。 – Louis

+0

如果你尝试没有“sinon =”?然后会发生什么? – LSR

+0

您必须使用您在第一个片段中显示的回叫表单。 – Louis

相关问题