title: How to unit test function called in service's constructor?
body: <p>How can I test, in the service's spec file, that a function is called in the constructor? For example:</p>
  <pre class="lang-js prettyprint-override"><code>@Injectable({
      providedIn: 'root'
  })
  export class myService {
    
  
      constructor() {
         this.myFunction();
      }
  
      myFunction(){}
  }
  </code></pre>
  <p>So how can I test that my function was called?</p>
  <pre><code>beforeEach(() =&gt; {
  TestBed.configureTestingModule({});
      service = TestBed.get(myService);
  
  </code></pre>
  <p>I can't spy on the service before the testbed.get, and I tried:</p>
  <pre class="lang-js prettyprint-override"><code>it('should demonstrate myFunction called in constructor', () =&gt; {
    const spy = spyOn (myService, 'myFunction');
    const serv = new myService();
  
    expect(spy).toHaveBeenCalled();
  });
  </code></pre>
  <p>But this is failing to say spy wasn't called!</p>
  <p>Any help would be most appreciated.</p>