我的Jasmine单元测试如下
describe('controllers', function () {
'use strict';
beforeEach(module('myapp.controllers'));
angular.mock.module('myapp.controllers', function ($provide) {
$provide.value('$localStorage', $localStorage);
});
it('should have a creationController', inject(function ($controller, _$rootScope_, localize) {
var scope = _$rootScope_.$new();
var localize = localize;
var myCtrl1 = $controller('creationController', {
$scope: scope,
localize: localize
});
expect(myCtrl1).toBeDefined();
}));
});
当我尝试执行测试时,我收到以下错误
Error: [$injector:unpr] http://errors.angularjs.org/1.2.20/$injector/unpr?p0=localizeProvider%20%3C-%20localize
有一个依赖称为" localize"正在控制器中使用。但是我无法将其注入本单元测试中。
知道如何解决这个问题吗?
答案 0 :(得分:0)
进样器寻找_componenrToBeInjected_
进样。如果你有一个服务名称localized
(你确定你有一个吗?)那么注射用
_ localize_
所以你的阻止应该是这样的。
it('should have a creationController', inject(function ($controller, _$rootScope_, _localize_) {
var scope = _$rootScope_.$new();
var localize = _localize_;
var myCtrl1 = $controller('creationController', {
$scope: scope,
localize: localize
});
expect(myCtrl1).toBeDefined();
}));