For testing purposes you might want to inject window.location object in your component.
You can achieve this with custom InjectionToken mechanism provided by Angular.

export const LOCATION_TOKEN = new InjectionToken<Location>('Window location object');

  providers: [
    { provide: LOCATION_TOKEN, useValue: window.location }
export class SharedModule {}


export class AppComponent {
    @Inject(LOCATION_TOKEN) public location: Location
  ) {}

继续阅读 30秒学会 Angular 片段 – Window Location injection