我怎样才能注入自定义角度服务而不将其模型化为打字稿中的测试?

时间:2016-01-26 16:24:50

标签: angularjs typescript jasmine

我的模块和测试声明如下所示,但是当我尝试将ContentBlocksService注入beforeEach时(mock.inject((ContentBlocksService)...它表示未知提供者ContentBlocksServiceProvider ...任何想法?

模块:

module projName.ContentBlocks {
 "use strict";

 console.log("contentBlocks.module: start");

 angular.module("projName.contentBlocks", [
   "ui.router",
   "ui.bootstrap",
   "ui.bootstrap.tpls",
   "textAngular",
   "as.sortable",

 // shared modules
   "projName.filters"
 ])

  .service("ContentBlocksService", ContentBlocksService)
  // etc

}

试验:

module projName.ContentBlocks {
  "use strict";

  describe("ContentBlocksDetailPageService", () => {

  beforeEach(mock.inject((_$http_, _$log_, _$q_, _$httpBackend_, _$rootScope_) => {
    log = _$log_;
    httpMock = _$httpBackend_;
    alertService = new Shared.AlertService(_$q_, _$log_);
    $q = _$q_;
    $http = _$http_;
    $rootScope = _$rootScope_;
  }));

  /// etc

1 个答案:

答案 0 :(得分:1)

beforeEach(mock.module('projName.contentBlocks'));
beforeEach(mock.inject(...))之前需要

才能在规范中加载模块。