私は Karma と Mocha を使ったテストの初心者です。次のコントローラーで単体テストを実行したい:
'use strict';
// common functionality
angular.module('app').controller('CommonCtrl', ['$scope', 'appConfig',
function ($scope, appConfig) {
$scope.$back = function() {
window.history.back();
};
$scope.Currencies = appConfig.currencies;
// todo: decide where this should go (appConfig?)
$scope.ctPaginationLabel = {
text: 'Einträge pro Seite:',
of: 'von'
}
}]);
これは私のテストクラスがどのように見えるかです:
describe 'CommonCtrl', ->
$controller = null
beforeEach ->
module 'app'
inject (_$controller_) ->
$controller = _$controller_
it 'error flag if scope is missing', ->
$scope = null
appConfig = null
controller = $controller 'CommonCtrl', { $scope: $scope, appConfig: appConfig }
controller.error.should.be.ok
しかし、次のエラーが表示されます。
27 11 2015 11:47:29.378:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/
27 11 2015 11:47:29.387:INFO [launcher]: Starting browser PhantomJS
27 11 2015 11:47:31.715:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket oF_wQ0cqLGkNs9cWAAAA with id 44252940
PhantomJS 1.9.8 (Mac OS X 0.0.0) CommonCtrl "before each" hook for "error flag if scope is missing" FAILED
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.7/$injector/modulerr?p0=app&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20 ...
...
at /Users/Marcel/Development/project/html/js/angular/angular.min.js:38
at m (/Users/Marcel/Development/project/html/js/angular/angular.min.js:7)
at h (/Users/Marcel/Development/project/html/js/angular/angular.min.js:38)
at fb (/Users/Marcel/Development/project/html/js/angular/angular.min.js:41)
at workFn (/Users/Marcel/Development/project/test/helpers/angular-mocks.js:2427)
at /Users/Marcel/Development/project/test/helpers/angular-mocks.js:2410
at /Users/Marcel/Development/project/test/unit/controllers/common.js:9
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.014 secs / 0.006 secs)
すべての依存関係をkarma.conf.jsに埋め込みました。私のテストクラスのどこが間違っていますか?