title: How to mock super.ngOnInit() in unit tests with Jasmine? How to create spy on Base / Parent class method to cover derived / child class code only?
body: <pre><code>export class Parent implements OnInit {
      ngOnInit(): void {
      // huge amount of different services calls
      }
  }
  
  export class Child extends Parent implements OnInit {
      ngOnInit(): void {
          super.ngOnInit();
          // a few more functions
      }
  }  
  </code></pre>
  
  <p>How to develop unit test to cover Child's ngOnInit not mocking all services functions for Parent ngOnInit?  </p>
  
  <p>My attempts were something like these:</p>
  
  <pre><code>let child: Child;
  const mockParent = {
      ngOnInit: jasmine.createSpy('ngOnInit')
  };
  child = new Child();  // base object is created already
  Object.getPrototypeOf(child) = jasmine.createSpy('Parent').and.callFake(() =&gt; mockParent);  // so this doesn't work
  </code></pre>