我开始用 Karma 编写一些测试,为了乞求,我决定尝试简单的测试。但是,我收到两个错误(一个与茉莉花有关,另一个与注入有关(尝试 angular.inject 时出现相同的错误):
two errors Firefox 22.0 (Windows) ConfigurationController encountered a declaration exception FAILED
TypeError: this.func.apply is not a function in
/adapter/lib/jasmine.js?1374202126000 (line 1145)
testacular.js:106
:9876/context.html:40
ReferenceError: inject is not defined in /var/lib/tomcat7/webapps/lunchtime/test/controllers/configuration-controller.js (line 7)
@/var/lib/tomcat7/webapps/lunchtime/test/controllers/configuration-controller.js:7
@/var/lib/tomcat7/webapps/lunchtime/test/controllers/configuration-controller.js:3
Firefox 22.0 (Windows):执行 1 of 1 (1 FAILED) (0.48 secs / 0.011 secs)
我有简单的控制器:
app.controller("ConfigurationController", ["$scope", "$http", function($scope, $http) {
$scope.configuration = {};
}]);
和简单的测试:
'use strict';
describe('ConfigurationController', function() {
var scope, ctrl;
//you need to indicate your module in a test
beforeEach(angular.module('AmphinicyLunch'));
beforeEach(inject(function($rootScope) {
scope = $rootScope.$new();
ctrl = $controller("ConfigurationController", {$scope: scope})
}));
it("should have defined configuration", function($scope) {
dump($scope.configuration);
expect($scope.configuration).toEqual({});
});
});