title: How to spyOn a method called in the constructor?
body: <p>I have a ionic project with a method in the constructor of a component that is called depending of a condition. I 'm using Jasmine and I want to spyOn that method to check if it is called.</p>
  
  <p>This is the constructor of the component:</p>
  
  <pre><code>export class MyComponent {
      public test: boolean;
  
      constructor(public service: MyService) {
          if(test) {
              service.getX();
          }
      }
  }
  </code></pre>
  
  <p>In my spec.ts I have to instantiate the component in order to spyOn the method but isn't work since the method has already been called in the constructor.</p>
  
  <pre><code>beforeEach(() =&gt; {
  
      fixture = TestBed.createComponent(MyComponent);
      component = fixture.componentInstance;
  
  });
  
  it('Test case #1', () =&gt; {
      component.test = true;
  
      spyOn(component.service, 'getX'); //The method has already been called in the constructor called in beforEach above
  
      expect(component.service.getX).toHaveBeenCalled();
  })
  </code></pre>
  
  <p>How can I spyOn a method called in the constructor?</p>