AngularJS模块JasmineJS中的依赖关系

时间:2016-02-25 01:44:36

标签: javascript angularjs jasmine

当我使用Jasmine和AngularJS时,我遇到了问题。

我在AngularJS中的app.js:

var app = angular.module('myApp', ['uiGmapgoogle-maps']);

在Jasmine中,我将在下面举例:

(function() {
    'use strict';

    beforeEach(
        function () {
            module('myApp');
        }
    );

    describe('GeoLocationController', 
        function () {

            var _controller,
                _scope,
                _service;

            beforeEach(inject(function($rootScope, $controller) {
                _scope = $rootScope.$new();

                _controller = $controller('GeoLocationController', { 
                    '$scope': _scope,
                    'GeoLocationService': _service
                });
            }));

            it('exists', inject(
                function ($controller) {
                    expect(_controller).toBeDefined();
                    expect(_controller).not.toBeNull();
                    expect(typeof _controller).toBe('object');
                }
            ));
        }
    );
}());

当我在我的应用Angular中删除了[' uiGmapgoogle-maps']时,Jasmine工作了。

我试试:

beforeEach(
    function () {
        module('uiGmapgoogle-maps');
        module('myApp');
    }
);

beforeEach(
    function () {
        module('uiGmapgoogle-maps', []);
        module('myApp', []);
    }
);

beforeEach(
    function () {
        module('myApp', ['uiGmapgoogle-maps']);
    }
);

谢谢大家!

0 个答案:

没有答案