这是我的代码:
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
答案 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_;
}));
});