相关疑难解决方法(0)

注射器已经创建.无法注册模块

我是Angular JS的新宠,并试图以适当的TDD方式制作出一些东西,但是在测试时我收到了这个错误:

注射器已经创建,无法注册模块!

这是我正在谈论的服务.

bookCatalogApp.service('authorService', ["$resource", "$q", function($resource, $q){

    var Author =$resource('/book-catalog/author/all',{},{
        getAll : { method: 'GET', isArray: true}
    });

    var authorService = {};

    authorService.assignAuthors = function(data){
        authorService.allAuthors = data;
    };

    authorService.getAll = function(){
        if (authorService.allAuthors)
            return {then: function(callback){callback(authorService.allAuthors)}}

        var deferred = $q.defer();
        Author.getAll(function(data){
            deferred.resolve(data);
            authorService.assignAuthors(data);
        });
        return deferred.promise;
    };

    return authorService;
}]);
Run Code Online (Sandbox Code Playgroud)

这是对上述服务的测试

describe("Author Book Service",function(){
    var authorService;
    beforeEach(module("bookCatalogApp"));
    beforeEach(inject(function($injector) {
        authorService = $injector.get('authorService');
    }));

    afterEach(function() {
        httpBackend.verifyNoOutstandingExpectation();
        httpBackend.verifyNoOutstandingRequest();
    });

    describe("#getAll", function() {
        it('should get all the authors for …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

44
推荐指数
2
解决办法
2万
查看次数

标签 统计

angularjs ×1

javascript ×1