Reputation: 85
I get the following error while running ng test even though I could run ng build --prod.
1. If 'app-navbar' is an Angular component, then verify that it is part of this module.
'app-navbar' is not a known element:
1. If 'app-navbar' is an Angular component, then verify that it is part of this module.
2. If 'app-navbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-navbar></app-navbar>"): ng:///DynamicTestModule/AppComponent.html@0:0
error properties: Object({ ngSyntaxError: true, ngParseErrors: [ 'app-navbar' is not a known element:
2. If 'app-navbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-navbar></app-navbar>"): ng:///DynamicTestModule/AppComponent.html@0:0 ] })
Error: Template parse errors:
at syntaxError (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:2175:1)
at TemplateParser.parse (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:11388:1)
at JitCompiler._parseTemplate (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25963:1)
at JitCompiler._compileTemplate (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25951:61)
at http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25895:1
at <Jasmine>
at JitCompiler._compileComponents (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25895:1)
at http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25815:1
at Object.then (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:2166:27)
at JitCompiler._compileModuleAndAllComponents (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25813:1)
if I have the navbar component outside the shared folder ng test works. but when doing large projects I need to put the components in different folders example core, shared , data.
Upvotes: 0
Views: 276
Reputation: 668
You need to add this component or the module containing this component in the test declaration like this:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppNavBar],
imports: [RouterTestingModule]
})
.compileComponents();
}));
Upvotes: 1