Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jasmine未能实例化Angular模块?_Javascript_Angularjs_Unit Testing_Jasmine - Fatal编程技术网

Javascript Jasmine未能实例化Angular模块?

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 = {

好的,我正在尝试使用Jasmine 2.2.0为AngularJS项目实现单元测试,但我无法为控制器实现一个基本的示例测试。感谢您的帮助

以下是控制器的代码(我拥有的最简单的代码):

下面是我正在尝试运行的规范文件:

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');