title: Error: Expected a spy, but got Function
body: <p>Here is my <strong>controller:</strong> </p>
  
  <pre><code>    export class testController  {
      static $inject: string[] = ["testService", "$mdDialog", "$state"];
      constructor(public _testService: services.testService, private _mdDialog: any, private _$state: any) {
          this.isCurrentlyEditing = false;
          this.activate();
      }
      }
  </code></pre>
  
  <p>Here is my <strong>unit test</strong> for that:</p>
  
  <pre><code>  import {test as service}  from './test.service';
    import {test as ctrl} from './test.controller';
  
    export function main() {
      describe("testController", () =&gt; {
  
      var mdDialog: angular.material.IDialogService;
      var state: ng.ui.IStateService;
      var testService: any;
      var controller: any;
  
      beforeEach(function () {
          angular.mock.module('comp.modules.addField');           
      });
      beforeEach(function () {
          testService = {
              showCLULayer: () =&gt; { }
          };
      });
  
      beforeEach(module('comp'));
      beforeEach(inject(($injector: any) =&gt; {
  
          mdDialog = $injector.get('$mdDialog');
          state = $injector.get('$state');
          testService = $injector.get('testService');
          controller = new ctrl.testController(testService, mdDialog, state);
      }));
  
      it("should Create Controller", () =&gt; {          
          controller = new ctrl.testController(testService, mdDialog, state);
          spyOn(testService, 'showCLULayer').and.callThrough();
          expect(controller).not.toBeNull();
          expect(controller.activate).toHaveBeenCalled();  
          ////error Expected a spy, but got Function.      
      });       
  
  });
  }
  </code></pre>
  
  <p>The test throws error when it goes to the line:    </p>
  
  <pre><code> expect(controller.activate).toHaveBeenCalled();
  </code></pre>
  
  <p>saying that Expected a spy, but got Function. Activate is a function that gets called when i call constructor of my controller which I am testing. Can some one point me in right direction please.</p>
  
  <p>Tried adding the line </p>
  
  <pre><code>    spyOn(controller, 'activate'); 
  </code></pre>
  
  <p>before expect, I am getting the following error.</p>
  
  <pre><code>   Expected spy activate to have been called.
     Error: Expected spy activate to have been called.
  </code></pre>