Skip to content

when running ng test - got a 'router-outlet' is not a known element - error - Angular 4 #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
henry-hz opened this issue Jul 14, 2017 · 9 comments
Labels

Comments

@henry-hz
Copy link

Trying to run "ng test" on angular4 starter application.

I am using :
node v8.1.4
npm 5.0.3

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.
2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<router-outlet></router-outlet>"): ng:///DynamicTestModule/AppComponent.html@0:0
@mokipedia
Copy link

mokipedia commented Jul 15, 2017

getting the same here,
using yarn 0.21.0, cloned gitrepo yesterday

@mokipedia
Copy link

mokipedia commented Jul 20, 2017

For everyone else having this issue:

in app.component.spec.ts

  • import {RouterTestingModule} from '@angular/router/testing'
  • add imports to TestBed
    beforeEach(() => { TestBed.configureTestingModule({ declarations: [ AppComponent ], imports: [ RouterTestingModule ] });

reference:

@ManfredGit
Copy link

using mokipedia's solution, not work for me.

@mukeshfull
Copy link

@mokipedia is awesome. My error gone.

@hmaiga
Copy link

hmaiga commented Feb 17, 2018

@mokipedia solution works fine for me, thxs guy 👍

@Qocotzxin
Copy link

@mokipedia Thanks, that's THE solution! Just in case someone uses the Atom's Angular snippet, the spec file does not include the "import" array by default so you will have to add it to the configureTestingModule by yourself, and include only the RouterTestingModule

@mokipedia
Copy link

mokipedia commented Mar 15, 2018

thats cool that it helps.
Just wanted to follow up for everyone else having this issues:
coreui seems to have moved angular5 development to a new repository (where this error is obviously fixed): https://github.com/mrholek/CoreUI-Angular

CDuPlooy pushed a commit to TripleParity/docks-ui that referenced this issue Jun 13, 2018
Removed router-outlets in new html files.
Moved things around a little.
Played with imports across modules to resolve last two tests failing.

References:
coreui/coreui-free-bootstrap-admin-template#202
https://stackoverflow.com/questions/41019109/error-no-provider-for-router-while-writing-karma-jasmine-unit-test-cases
@adv2028
Copy link

adv2028 commented Aug 18, 2018

@mokipedia It worked! Thanks!

jauninb added a commit to jauninb/bnpp-hackathon-devopsonthecloud-front that referenced this issue Jul 2, 2019
@stale
Copy link

stale bot commented Jun 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 24, 2020
@stale stale bot closed this as completed Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants