0

I am trying to run a unit test which is testing a component with an injected router. This is my set up code...

TestBed.configureTestingModule({
      declarations: [PeopleComponent, PersonComponent],
      providers: [
        {
          provide: Http, useFactory: (backend, options) => {
          return new Http(backend, options);
        },
          deps: [MockBackend, BaseRequestOptions]
        },
        MockBackend,
        BaseRequestOptions,
        PeopleRepository,
        PeopleViewModelLoader,
        PersonViewModelLoader,
        {provide: APP_BASE_HREF, useValue: '/'}
      ],
      imports:      [BrowserModule,HttpModule, RouterModule.forRoot([
        { path: '', component: PeopleComponent },
        { path: 'person/:id', component: PersonComponent }
      ])]
    });

However I end up with the following error...

inline template:0:0 caused by: Bootstrap at least one component before injecting Router.

How do I bootstrap the component before injecting the APP_BASE_HREF ? It doesn't make any sense what if I don't have another component, for example if I had only one component in my app?

Exitos
  • 29,230
  • 38
  • 123
  • 178
  • 1
    The duplicate link by @GünterZöchbauer doesn't provide the correct solution (the post isn't even about testing). Please see [this post](http://stackoverflow.com/a/39908040/2587435) – Paul Samsotha Oct 25 '16 at 05:01
  • @peeskillet thanks for the hint. Didn't check properly :-/. See also http://stackoverflow.com/questions/39148492/angular-2-bootstrap-at-least-one-component-before-injecting-router – Günter Zöchbauer Oct 25 '16 at 05:02
  • 1
    @GünterZöchbauer we all have those moments :-) – Paul Samsotha Oct 25 '16 at 05:06

0 Answers0