title: Test Angular. TypeError: this._platformStrategy.getBaseHref is not a function
body: <p>I want to test routing. I tried this script:</p>
  
  <pre><code>describe('Router: App', () =&gt; {
      let location: Location;
      let router: Router;
      let fixture;
      beforeEach(() =&gt; {
          TestBed.configureTestingModule({
              declarations: [
                  AlarmsTableComponent,
                  AddAlarmsFormComponent,
                  EditAlarmsFormComponent,
                  LoginComponent,
                  DataFilterPipe
              ],
              imports: [RouterTestingModule, DataTableModule, ReactiveFormsModule, FormsModule, HttpClientTestingModule, HttpModule],
              providers: [Location, LocationStrategy, AlarmsService, DataFilterPipe, AuthService, ConnectionBackend, HttpModule,
                  {
                      provide: APP_BASE_HREF, useValue: '/page' }
                  ]
          });
  
          router = TestBed.get(Router);
          location = TestBed.get(Location);
  
          fixture = TestBed.createComponent(MainComponent);
          router.initialNavigation();
      });
      it('navigate to "" redirects you to /page', fakeAsync(() =&gt; {
          router.navigate(['page']);
          tick();
          expect(location.path()).toBe('/page');
      }));
  });
  </code></pre>
  
  <p>When I <code>ng test</code> the result is this error:</p>
  
  <blockquote>
    <p>TypeError: this._platformStrategy.getBaseHref is not a function</p>
  </blockquote>
  
  <p>Edit:</p>
  
  <pre><code>describe('Router: App', () =&gt; {
      let location: Location;
      let router: Router;
      let fixture;
      beforeEach(() =&gt; {
          TestBed.configureTestingModule({
              declarations: [
                  AlarmsTableComponent,
                  AddAlarmsFormComponent,
                  EditAlarmsFormComponent,
                  LoginComponent,
                  DataFilterPipe
              ],
              imports: [RouterTestingModule, DataTableModule, ReactiveFormsModule, FormsModule, HttpClientTestingModule, HttpModule],
   providers: [Location, AuthService, AlarmsService, DataFilterPipe,
              {provide: LocationStrategy, useClass: PathLocationStrategy }],
          });
  
          router = TestBed.get(Router);
          location = TestBed.get(Location);
  
          fixture = TestBed.createComponent(MainComponent);
          router.initialNavigation();
      });
      it('navigate to "" redirects you to /page', fakeAsync(() =&gt; {
          router.navigate(['page']);
          tick();
          expect(location.path()).toBe('/page');
      }));
  });
  </code></pre>
  
  <p>And now show this:</p>
  
  <blockquote>
    <p>Error: No base href set. Please provide a value for the APP_BASE_HREF
    token or add a base element to the document.</p>
  </blockquote>