2016-10-01 3 views
15

ich ein neues Projekt mit kantigem 2.0 RTM mit kantig CLI 1.0.0-beta 16 erstellt:Angular 2 + ng Test: 'X' ist keine bekannte Komponente

ng init

und lief dann:

ng generate component my-new-component

und dann lief:

ng test

und bekam dies:

'app-my-new-component' is not a known element: 
1. If 'app-my-new-component' is an Angular component, then verify that it is part of this module. 
2. If 'app-my-new-component' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. (" 
</h1> 
<p>The mean of life is {{answer}}</p> 
[ERROR ->]<app-my-new-component></app-my-new-component>"): [email protected]:0 
Error: Template parse errors: 
    at TemplateParser.parse (http://localhost:9877/_karma_webpack_/0.bundle.js:8669:19) 
    at RuntimeCompiler._compileTemplate (http://localhost:9877/_karma_webpack_/0.bundle.js:17854:51) 
    at http://localhost:9877/_karma_webpack_/0.bundle.js:17777:83 
    at Set.forEach (native) 
    at compile (http://localhost:9877/_karma_webpack_/0.bundle.js:17777:47) 
    at RuntimeCompiler._compileComponents (http://localhost:9877/_karma_webpack_/0.bundle.js:17779:13) 
    at RuntimeCompiler._compileModuleAndAllComponents (http://localhost:9877/_karma_webpack_/0.bundle.js:17696:37) 
    at RuntimeCompiler.compileModuleAndAllComponentsSync (http://localhost:9877/_karma_webpack_/0.bundle.js:17684:21) 
    at TestingCompilerImpl.compileModuleAndAllComponentsSync (http://localhost:9877/_karma_webpack_/0.bundle.js:24662:35) 
    at TestBed._initIfNeeded (webpack:///home/adam/monctonug/~/@angular/core/bundles/core-testing.umd.js:1059:0 <- src/test.ts:4568:40) 

Ich habe versucht, Komponenten Neuordnen, half nicht. Was ist der richtige Weg, um dieses Problem zu beheben?

+0

Mit dem gleichen Problem. Ich habe offene/geschlossene Probleme mit GitHub im Zusammenhang mit diesem Fehler untersucht, aber keine Lösung gefunden, um das Problem zu beheben. – ajurasz

Antwort

25

ich das gleiche Problem konfrontiert war und es sich herausstellen, dass für die Tests müssen Sie auch gebrauchte Komponenten deklarieren:

beforeEach(() => { 
    TestBed.configureTestingModule({ 
     declarations: [ 
     AppComponent, 
     MyNewComponent  
     ], 
    }); 
+0

Das war das Problem. Ich habe andere Probleme, aber das hat dieses eine gelöst. –

+0

Ich habe auch andere Probleme in meinem Leben, die diese Antwort nicht beheben konnte, aber es hat dieses für mich gelöst! Gute Arbeit. –

Verwandte Themen