title: Angular 2 testing with global providers
body: <p>I am testing a lot of components in an angular cli project, and I'm using <code>RouterTestingModule</code> in some of them to stub the router. I'd like to just add <code>RouterTestingModule</code> to all tests so I don't have to selectively add it.</p>
  
  <p>I added it to the test setup in <code>test.js</code> like below, but it does not seem to be included in the test modules for the components. Is this the correct way to include "global" providers?</p>
  
  <pre><code>Promise.all([
      System.import('@angular/core/testing'),
      System.import('@angular/platform-browser-dynamic/testing'),
      System.import('@angular/router/testing'),
  ])
      // First, initialize the Angular testing environment.
      .then(([testing, testingBrowser, testingRouter]) =&gt; {
          testing.getTestBed().initTestEnvironment(
              testingBrowser.BrowserDynamicTestingModule,
              testingBrowser.platformBrowserDynamicTesting(),
              testingRouter.RouterTestingModule,
          );
      })
      // Then we find all the tests.
      .then(() =&gt; require.context('./', true, /\.spec\.ts/))
      // And load the modules.
      .then(context =&gt; context.keys().map(context))
      // Finally, start Karma to run the tests.
      .then(__karma__.start, __karma__.error);
  </code></pre>
  
  <p>The docs say this about <code>initTestEnvironment</code>:</p>
  
  <blockquote>
    <p>This may only be called once, to set up the common providers for the
    current test suite on the current platform.</p>
  </blockquote>