unit testing - Angular2 Cli Test (Webpack) Erros: "Error: Template parse errors" -
this appmodule:
import { browsermodule } '@angular/platform-browser'; import { ngmodule, custom_elements_schema } '@angular/core'; import { formsmodule } '@angular/forms'; import { httpmodule } '@angular/http'; import { appcomponent } './app.component'; import { citiescomponent } './cities/cities.component'; @ngmodule({ declarations: [ appcomponent, citiescomponent ], imports: [ browsermodule, formsmodule, httpmodule, ], providers: [], bootstrap: [appcomponent], schemas: [custom_elements_schema] }) export class appmodule { }
citiescomponent
simple module. , use component inside appcomponent
.
application builds , works without errors; when execute ng test
fails error:
error: template parse errors: 'app-cities' not known element: 1. if 'app-cities' angular component, verify part of module. 2. if 'app-cities' web component add "custom_elements_schema" '@ngmodule.schema' of component suppress message. ("<main> <h1>hello angular 2 app webpack</h1> <div class="ui segment raised"> hello </div> [error ->]<app-cities></app-cities> </main> "): appcomponent@0:99 in config/karma-test-shim.js (line 181) parse@webpack:///~/@angular/compiler/bundles/compiler.umd.js:8813:0 <- config/karma-test-shim.js:181:50110 _compiletemplate@webpack:///~/@angular/compiler/bundles/compiler.umd.js:16978:0 <- config/karma-test-shim.js:186:8984 webpack:///~/@angular/compiler/bundles/compiler.umd.js:17065:0 <- config/karma-test-shim.js:186:10862 foreach@webpack:///~/core-js/modules/_typed-array.js:467:0 <- config/karma-test-shim.js:2:50965 s@webpack:///~/@angular/compiler/bundles/compiler.umd.js:17061:62 <- config/karma-test-shim.js:186:10831 _compilecomponents@webpack:///~/@angular/compiler/bundles/compiler.umd.js:16887:0 <- config/karma-test-shim.js:186:6610 _compilemoduleandallcomponents@webpack:///~/@angular/compiler/bundles/compiler.umd.js:16828:37 <- config/karma-test-shim.js:186:4786 compilemoduleandallcomponentssync@webpack:///~/@angular/compiler/bundles/compiler.umd.js:16804:0 <- config/karma-test-shim.js:186:4350 compilemoduleandallcomponentssync@webpack:///~/@angular/compiler/bundles/compiler.umd.js:1:0 <- config/karma-test-shim.js:150:24366 _initifneeded@webpack:///~/@angular/core/bundles/core.umd.js:1:0 <- config/karma-test-shim.js:78:22512 createcomponent@webpack:///~/@angular/core/bundles/core.umd.js:1:0 <- config/karma-test-shim.js:78:25044 createcomponent@webpack:///~/@angular/core/bundles/core.umd.js:1:0 <- config/karma-test-shim.js:78:20648 webpack:///~/@angular/core/bundles/core-testing.umd.js:1:0 <- config/karma-test-shim.js:66:10991 invoke@webpack:///config/karma-test-shim.js:8711:32 <- config/karma-test-shim.js:24:40262 oninvoke@webpack:///~/zone.js/dist/proxy.js:75:0 <- config/karma-test-shim.js:38:1630 invoke@webpack:///config/karma-test-shim.js:8711:32 <- config/karma-test-shim.js:24:40216 run@webpack:///config/karma-test-shim.js:8711:32 <- config/karma-test-shim.js:24:34612 webpack:///~/zone.js/dist/jasmine-patch.js:28:0 <- config/karma-test-shim.js:52:655 execute@webpack:///config/karma-test-shim.js:9163:32 <- config/karma-test-shim.js:52:3370 execute@webpack:///config/karma-test-shim.js:9163:32 <- config/karma-test-shim.js:52:3370 webpack:///config/karma-test-shim.js:9163:32 <- config/karma-test-shim.js:52:3480 invoketask@webpack:///config/karma-test-shim.js:8711:32 <- config/karma-test-shim.js:24:40940 runtask@webpack:///config/karma-test-shim.js:8711:32 <- config/karma-test-shim.js:24:35224 drainmicrotaskqueue@webpack:///~/zone.js/dist/zone.js:584:0 <- config/karma-test-shim.js:24:19813 s@webpack:///~/core-js/modules/_typed.js:25:0 <- config/karma-test-shim.js:2:22237 webpack:///~/core-js/modules/_typed-buffer.js:12:0 <- config/karma-test-shim.js:2:22359 u@webpack:///~/core-js/modules/_microtask.js:18:0 <- config/karma-test-shim.js:2:15867
any idea? using angular2-2.0 , "angular-cli": "1.0.0-beta.15"
in app.component.spec.ts
, should declare citiescomponent
:
import { testbed, async } '@angular/core/testing'; import { appcomponent } './app.component'; import { citiescomponent } './cities/cities.component'; describe('appcomponent', () => { beforeeach(() => { testbed.configuretestingmodule({ declarations: [ appcomponent, citiescomponent // => add here ], }); testbed.compilecomponents(); }); // });
Comments
Post a Comment