Skip to content

Unit test error: Router outlet is not a known element #1004

@gaurav2887

Description

@gaurav2887

Note: for support questions, please use one of these channels: Chat: AngularClass.slack or Twitter: @AngularClass

  • I'm submitting a ...
    [x ] bug report

I am getting following error when running a unit test:

Error: Template parse errors:
'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular component, then verify that it is part of this module.

My unit test code:


import {
    inject,
    TestBed
} from '@angular/core/testing';

// Load the implementations that should be tested
import { App } from './app.component';
import { AppState } from './app.service';
import { Renderer } from '@angular/core';
import { Router, RouterOutlet } from "@angular/router";

class MockRouter { public navigate() {}; }

describe('App', () => {

    // provide our implementations or mocks to the dependency injector
    beforeEach(() => TestBed.configureTestingModule({
        declarations: [ App ],
        providers: [
            AppState,
            Renderer,
            {provide: Router,  useClass: MockRouter },
            RouterOutlet
        ]}));

    it('should have a url', inject([ App ], (app: App) => {
        expect(app.name).toEqual('test');
    }));

});

My app.html has router outlet:

        <router-outlet></router-outlet>

I tried removing RouterOutlet as well in unit test and it did not work. Has anyone experienced this issue and help me with the solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions