Javascript Jasmine未能实例化Angular模块?
好的,我正在尝试使用Jasmine 2.2.0为AngularJS项目实现单元测试,但我无法为控制器实现一个基本的示例测试。感谢您的帮助 以下是控制器的代码(我拥有的最简单的代码): 下面是我正在尝试运行的规范文件:Javascript Jasmine未能实例化Angular模块?,javascript,angularjs,unit-testing,jasmine,Javascript,Angularjs,Unit Testing,Jasmine,好的,我正在尝试使用Jasmine 2.2.0为AngularJS项目实现单元测试,但我无法为控制器实现一个基本的示例测试。感谢您的帮助 以下是控制器的代码(我拥有的最简单的代码): 下面是我正在尝试运行的规范文件: describe('myApp', function() { describe('controller', function() { var scope, controller; var mockAlertService = {
describe('myApp', function() {
describe('controller', function() {
var scope, controller;
var mockAlertService = { // simple mock service
closeAlert: function(e) {
console.log('close');
},
getAlertList: function() {
return [];
}
}
beforeEach(function() {
angular.mock.module('app.alert');
});
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('AlertCtrl as alertctrl', {
$scope: scope,
AlertService: mockAlertService
});
}));
it('should work: ', function() {
expect(true).toBe(true);
});
});
});
运行测试时,我收到以下错误消息:
Error: [$inject:modulerr] Failed to instantiate module app.alert due to:
[$injector:nomod] Module 'app.alert' is not available! You either misspelled
the module name or forgot to load it.
喷油器似乎不知道app.alert模块,这意味着它没有被正确模拟?我将angular-mocks.js文件包含在我的SpecRunner.html文件中。有人能看到我做错了什么吗?你没有拼写错
app.alert
和app.alerts
:
angular.module('app.alerts')
.controller('AlertCtrl', AlertCtrl);
及
…而且我很笨。谢谢
angular.module('app.alerts')
.controller('AlertCtrl', AlertCtrl);
angular.mock.module('app.alert');