Fixing ‘router-outlet’ is not a known element for Jasmine in Angular

When you start creating an application using Angular CLI and want to start testing your application using Jasmine you may start to find you are getting the following error:-

If 'router-outlet' is an Angular component, then verify that it is part of this module.

There is a simple fix for this issue.

When you include:-

<router-outlet></router-outlet>

inside your template you will need to import the RouterTestingModule inside your components spec file:-

beforeEach(async(() => {
  TestBed.configureTestingModule({
    declarations: [ PublicComponent ],
    imports: [ RouterTestingModule ],
  })
  .compileComponents();
}));

Now when you run ng test again you will no longer receive the error.

Good luck.

Sidebar Menu