我是使用 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中嵌入了所有依赖项。我的测试课的错误在哪里?