title: Mocking a service thats provided in a component controller in a unit test
body: <p>This is the error I'm seeing when trying to run my unit test ..</p>
  
  <pre><code>Expected undefined to be defined.
  TypeError: undefined is not an object (evaluating '$rootScope.$digest')
  
  Module 'ThirdPartyModule' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
  </code></pre>
  
  <p>Any ideas how to mock the <code>testService</code> so that I can still compile my component?</p>
  
  <p>test.component.spec.ts</p>
  
  <pre><code>import { TestModule } from '../index';
  
  describe('Component: testComponent', () =&gt; {
  
    let $rootScope: angular.IScope;
    let element: angular.IAugmentedJQuery;
  
    beforeEach(() =&gt; {
      angular.mock.module('ui.router');
      angular.mock.module(TestModule.name);
    });
  
    beforeEach(inject((
      _$rootScope_: angular.IScope,
      $compile: angular.ICompileService,
      _$state_: angular.ui.IStateService) =&gt; {
      $rootScope = _$rootScope_;
      element = angular.element('&lt;test&gt;&lt;/test&gt;');
      element = $compile(element)($rootScope);
    }));
  
    it('should verify component compiled and rendered template', () =&gt; {
      expect(element).toBeDefined();
      $rootScope.$digest();
      let link = element.find('a');
      expect(link.text()).toContain('Click this link!');
    });
  });
  </code></pre>
  
  <p>test.module.ts</p>
  
  <pre><code>import { TestComponent } from './test';
  
  export let TestModule: ng.IModule = angular.module(
    'test', // my module name
    ['ui.router', 'ThirdPartyModule']) // dependencies, ThirdPartyModule contains testService
    .component('test', new TestComponent());
  </code></pre>
  
  <p>test.component.ts</p>
  
  <pre><code>import { TestComponentController } from './test.component.controller';
  
  export class TestComponent implements ng.IComponentOptions {
    public template: string = '&lt;a ng-if="ctrl.serviceReturned"&gt;Click this link!&lt;/a&gt;';
    public controller: Function = TestComponentController;
    public controllerAs: string = 'ctrl';
  
    constructor() {}
  }
  </code></pre>
  
  <p>test.component.controller.ts</p>
  
  <pre><code>export class TestComponentController {
  
    public serviceReturned: boolean = false;
  
    constructor(private testService: any) {
      if (this.testService.isDone()) {
        this.serviceReturned = true;
      }
    }
  }
  
  TestComponentController.$inject = ['testService'];
  </code></pre>