Nick B
Nick B

Reputation: 715

How can I inject a custom angular service without mocking it into a test in typescript?

My modules and tests are declared as shown below, but when I try to inject ContentBlocksService into beforeEach(mock.inject((ContentBlocksService)... it says Unknown provider ContentBlocksServiceProvider... any ideas?

Modules:

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

}

Tests:

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

Upvotes: 0

Views: 50

Answers (1)

Estus Flask
Estus Flask

Reputation: 223239

beforeEach(mock.module('projName.contentBlocks'));

is required before beforeEach(mock.inject(...)) in order for the module to be loaded in specs.

Upvotes: 1

Related Questions