错误:[$ injector:unpr]未知提供者:a

时间:2014-11-27 03:11:57

标签: javascript angularjs jasmine

这是我的代码:

app.factory('assignmentAttachments', function() {


});

describe("test", function() {
    // arrange variable
    var assignmentAttachments;

    // inject service
     beforeEach(inject(function(_assignmentAttachments_) {
        assignmentAttachments = _assignmentAttachments_;
     })); 

    describe("test", function() {
        it("test", function() {
            // arrange

        })
    });

});

我收到以下错误:

  

错误:[$ injector:unpr]未知提供商:   assignmentAttachmentsProvider< - assignmentAttachments     http://errors.angularjs.org/1.2.27/ $注射器/ unpr?P0 = assignmentAttachmentsProvider%20%3 C-%20assignmentAttachments

1 个答案:

答案 0 :(得分:2)

确保您已导入注册assignmentAttachments的模块。例如,如果在assignmentAttachments模块中注册了app,请执行以下操作:

var app = angular.module('app', [])
app.factory('assignmentAttachments', ...});

然后你必须在测试中导入该模块:

describe("test", function() {
    ...

    beforeEach(module('app')); // <== add this line

    // inject service
    beforeEach(inject(function(_assignmentAttachments_) {
        assignmentAttachments = _assignmentAttachments_;
    })); 
});