1
我一直在寻找几个小时的解决方案,但我不能使它的工作。 我有一个控制器定义为:AngularJS - 单元测试 - 测试控制器与自定义服务
(function() {
'use strict';
angular.module('spaSkeleton.parCCP')
.controller('ParCCPCtrl', function ($scope, $mdToast, AnosLetivosService, UnidadesOrganicasService, CursosService, RelatoriosService, PareceresService) {
//my code
,我要测试的这款控制器,但我有所有这些服务,我必须注入。 的服务之一是这样的:
var app = angular.module('sigq.anosLetivos', []);
app.service('AnosLetivosService', function (Restangular) {
this.getAnosLetivos = function() {
return Restangular.all("anos-letivos").getList({"sort": "ano_inicio"});
};
});
,并在我的测试文件,我有这样的:
describe('Parecer Controllers', function(){
beforeEach(module('spaSkeleton.parCCP'));
beforeEach(function() {
module('namespace.anosLetivos');
module('namespace.unidadesOrganicas');
module('namespace.cursos');
module('namespace.relatorios');
module('namespace.pareceres');
module('namespace.landingPage');
});
describe('Parecer Ctrl', function(){
var scope, ctrl, $httpBackend;
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
$httpBackend = _$httpBackend_;
$httpBackend.expectGET(...).respond(...);
scope = $rootScope.$new();
ctrl = $controller('ParCtrl', {$scope: scope});
}));
});
});
我想就如何将这些服务注入到控制器,所以我可以测试一些帮助它。我已经尝试了很多东西。 https://docs.angularjs.org/tutorial/step_11这看起来很简单,但不起作用,他甚至没有注入东西,或者他?我知道在教程中的作品,但我不知道如何以及为什么,我不能让它在我的项目上工作。
欢迎任何帮助:d