2016-03-20 5 views
0

これはカルマジャスミンとうまくいっていますが、カルマ - モカとはうまく動作しません。モジュール名 "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/lib/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' 
    } 

}); 

}

MYサンプルコード:::

'use strict'; 

describe('calendarHelper', function() { 
    beforeEach(module('eventsApp')); 

    it('should return January when given a zero',  inject(function(calendarHelper) { 
     expect(calendarHelper.getMonthName(0)).toBe('January'); 
    })) 
}); 
+3

[Uncaught Error:モジュール名 "lib/chai"がコンテキスト用にまだロードされていません:use require(\ [\])](http://stackoverflow.com/questions/36104971/uncaught-error -module-name-lib-chai-has-been-loaded-yet-for-context-use) – Louis

答えて

0

私はジャスミンに似たような状況に出くわしました。 私のソリューションを紹介したいと思います。

エラーメッセージに書かれている内容を試してください。ウェブサイトへのリンクがあります:あなたのspecファイル内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. 
}); 

のCoffeeScriptでジャスミンとSinonのために書かれた私の場合は、次のようになります。

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

私がすることができます私の単体テストではsinonをオブジェクトとして使用し、sinonとjasmin-sinonのドキュメントにも従うことができます。

+0

複数の質問に同じ回答を投稿しないでください。 1つの良い答えを投稿し、投票/フラグを立てて他の質問を重複として閉じます。質問が重複していない場合は、*あなたの質問に対する回答を調整してください。* –

+0

質問はなぜ以前には報告されていませんか? – LSR

関連する問題