title: Angular Testing: How to provide Injector?
body: <p>I try to build an Angular component which depends on an Injector providing an InjectorToken:</p>
  
  <pre><code>import { Component, Injector, InjectionToken } from '@angular/core';
  
  const TOKEN = new InjectionToken&lt;string&gt;('token');
  
  @Component({
    selector: 'app-test',
    templateUrl: './test.component.html',
    styleUrls: ['./test.component.scss']
  })
  export class TestComponent {
    constructor(injector: Injector) {
      injector.get(TOKEN);
    }
  }
  </code></pre>
  
  <p>However, I can not get the test running for this component and get following error:</p>
  
  <pre><code>NullInjectorError: StaticInjectorError(DynamicTestModule)[InjectionToken token]: 
    StaticInjectorError(Platform: core)[InjectionToken token]: 
      NullInjectorError: No provider for InjectionToken token!
  </code></pre>
  
  <p>The following approach to provide the Injector in the TestBed didn't work:</p>
  
  <pre><code>TestBed.configureTestingModule({
    declarations: [ TestComponent ],
    providers: [
      { provide: Injector, useValue: Injector.create({providers: [
        {
          provide: new InjectionToken&lt;string&gt;('token'),
          useValue: '',
          deps: []
        }
      ]}) }
    ]
  })
  </code></pre>
  
  <p>How can I setup the test environment correctly?</p>