title: In Jasmine unit tests: Can't resolve all parameters for TestFormInputComponentBase
body: <p>I'm new to unit testing Angular application and I'm trying to test my first component. Actually, I'm trying to test an abstract base class that is used by the actual components, so I've created a simple Component in my spec based on that and I'm using that to test it.
  But there is a dependency to handle (<code>Injector</code>) and I'm not stubbing it out correctly because when I try to run the test I get this error:</p>
  <p><code>Can't resolve all parameters for TestFormInputComponentBase</code></p>
  <p>But I'm not sure what I have missed?
  Here is the spec:</p>
  <pre class="lang-js prettyprint-override"><code>import { GenFormInputComponentBase } from './gen-form-input-component-base';
  import { Injector, Component } from '@angular/core';
  import { TestBed } from '@angular/core/testing';
  
  // We cannot test an abstract class directly so we test a simple derived component
  @Component({
      selector: 'test-form-input-component-base'
  })
  class TestFormInputComponentBase extends GenFormInputComponentBase {}
  
  let injectorStub: Partial&lt;Injector&gt;;
  
  describe('GenFormInputComponentBase', () =&gt; {
      let baseClass: TestFormInputComponentBase;
      let stub: Injector;
  
      beforeEach(() =&gt; {
          // stub Injector for test purpose
          injectorStub = {
              get(service: any) {
                  return null;
              }
          };
  
          TestBed.configureTestingModule({
              declarations: [TestFormInputComponentBase],
              providers: [
                  {
                      provide: Injector,
                      useValue: injectorStub
                  }
              ]
          });
  
          // Inject both the service-to-test and its stub dependency
          stub = TestBed.get(Injector);
          baseClass = TestBed.get(TestFormInputComponentBase);
      });
  
      it('should validate required `field` input on ngOnInit', () =&gt; {
          expect(baseClass.ngOnInit()).toThrowError(
              `Missing 'field' input in AppFormInputComponentBase`
          );
      });
  });
  </code></pre>
  <p>This is the <code>GenFormInputComponentBase</code> class that I'm trying to test:</p>
  <pre class="lang-js prettyprint-override"><code>import { Input, OnInit } from '@angular/core';
  import { FormGroup } from '@angular/forms';
  import { GenComponentBase } from './gen-component-base';
  
  export abstract class GenFormInputComponentBase extends GenComponentBase
      implements OnInit {
      @Input() form: FormGroup | null = null;
      @Input() field: string | null = null;
  
      @Input() label: string | null = null;
      @Input() required: boolean | null = null;
  
      @Input('no-label') isNoLabel: boolean = false;
  
      ngOnInit(): void {
          this.internalValidateFields();
      }
  
      /**
       * Validates that the required inputs are passed to the component.
       * Raises clear errors if not, so that we don't get lots of indirect, unclear errors
       * from a mistake in the template.
       */
      protected internalValidateFields(): boolean {
          if (null == this.field) {
              throw Error(`Missing 'field' input in AppFormInputComponentBase`);
          }
  
          if (null == this.label &amp;&amp; !this.isNoLabel) {
              throw Error(
                  `Missing 'label' input in AppFormInputComponentBase for '${
                      this.field
                  }'.`
              );
          }
  
          if (null == this.form) {
              throw Error(
                  `Missing 'form' input in AppFormInputComponentBase for '${
                      this.field
                  }'.`
              );
          }
  
          return true;
      }
  }
  </code></pre>
  <p>And <code>GenComponentBase</code> has the dependency that I'm trying to stub out</p>
  <pre class="lang-js prettyprint-override"><code>import { Injector } from '@angular/core';
  import { LanguageService } from 'app/shared/services';
  
  declare var $: any;
  
  export abstract class GenComponentBase {
      protected languageService: LanguageService;
  
      constructor(injector: Injector) {
          this.languageService = injector.get(LanguageService);
      }
  
      l(key: string, ...args: any[]) {
          return this.languageService.localize(key, args);
      }
  }
  </code></pre>
  <p>Any help would be appreciated. Thanks!</p>
  <p><strong>Update:</strong></p>
  <p>By adding a constructor to <code>TestFormInputComponentsBase</code> I can stub out the <code>LanguageService</code> and it works fine like that. But if I try to stub out the <code>Injector</code>, it will get ignored and it tries to use the real injector anyway.</p>
  <pre class="lang-js prettyprint-override"><code>@Component({})
  class TestFormInputComponent extends GenesysFormInputComponentBase {
      constructor(injector: Injector) {
          super(injector);
      }
  }
  
  describe('GenesysFormInputComponentBase (class only)', () =&gt; {
      let component: TestFormInputComponent;
  
      beforeEach(() =&gt; {
          TestBed.configureTestingModule({
              providers: [
                  TestFormInputComponent,
                  {
                      provide: Injector,
                      useObject: {}
                  }
              ]
          });
  
          component = TestBed.get(TestFormInputComponent);
      });
  
      it('should validate required field inputs on ngOnInit', () =&gt; {
          expect(() =&gt; component.ngOnInit()).toThrowError(
              `Missing 'field' input in GenesysFormInputComponentBase.`
          );
      });
  });
  </code></pre>
  <p>I would expect to get some error due to the fact that the mock/stub injector provided is an empty object. But I get an error from the real injector. Can the injector simply not be mocked?</p>
  <pre><code>    Error: StaticInjectorError(DynamicTestModule)[LanguageService]: 
      StaticInjectorError(Platform: core)[LanguageService]: 
      NullInjectorError: No provider for LanguageService!
  </code></pre>