I am trying to create a model to back an Angular 2 app. I am new to Angular2, so please bear with me.
The model is a port from an older Java code base that we want to move to TypeScript. In doing so, we are recreating tests that would be classified as "isolated" test.
Issue:
After adding an isolated test, all Angular2 tests from the seed fail with similar errors in Karma:
Chrome 59.0.3071 (Windows 10 0.0.0) Home should have a title FAILED
Failed: Unexpected value 'HomeComponent' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
Error: Unexpected value 'HomeComponent' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
at syntaxError (webpack:///~/@angular/compiler/@angular/compiler.es5.js:1540:21 <- config/spec-bundle.js:33745:34) [ProxyZone]
at webpack:///~/@angular/compiler/@angular/compiler.es5.js:14542:0 <- config/spec-bundle.js:46747:40 [ProxyZone]
at Array.forEach (<anonymous>) [ProxyZone]
at CompileMetadataResolver.getNgModuleMetadata (webpack:///~/@angular/compiler/@angular/compiler.es5.js:14524:0 <- config/spec-bundle.js:46729:54) [ProxyZone]
at JitCompiler._loadModules (webpack:///~/@angular/compiler/@angular/compiler.es5.js:25630:25 <- config/spec-bundle.js:57835:66) [ProxyZone]
...snip...
at Zone.run (webpack:///~/zone.js/dist/zone.js:125:0 <- config/spec-bundle.js:70398:43) [<root> => ProxyZone]
at Object.<anonymous> (webpack:///~/zone.js/dist/jasmine-patch.js:102:0 <- config/spec-bundle.js:69881:34) [<root>]
at ZoneQueueRunner.jasmine.QueueRunner.ZoneQueueRunner.execute (webpack:///~/zone.js/dist/jasmine-patch.js:132:0 <- config/spec-bundle.js:69911:42) [<root>]
at Zone.runTask (webpack:///~/zone.js/dist/zone.js:165:0 <- config/spec-bundle.js:70438:47) [<root> => <root>]
at drainMicroTaskQueue (webpack:///~/zone.js/dist/zone.js:593:0 <- config/spec-bundle.js:70866:35) [<root>]
at <anonymous> [<root>]
Error: Unexpected value 'HomeComponent' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.
at syntaxError (webpack:///~/@angular/compiler/@angular/compiler.es5.js:1540:21 <- config/spec-bundle.js:33745:34) [ProxyZone]
at webpack:///~/@angular/compiler/@angular/compiler.es5.js:14542:0 <- config/spec-bundle.js:46747:40 [ProxyZone]
at Array.forEach (<anonymous>) [ProxyZone]
at CompileMetadataResolver.getNgModuleMetadata (webpack:///~/@angular/compiler/@angular/compiler.es5.js:14524:0 <- config/spec-bundle.js:46729:54) [ProxyZone]
...snip...
at Function.TestBed.createComponent (webpack:///~/@angular/core/@angular/core/testing.es5.js:610:0 <- config/spec-bundle.js:17189:29) [ProxyZone]
at Object.<anonymous> (webpack:///src/app/home/home.component.spec.ts:43:0 <- config/spec-bundle.js:73448:37) [ProxyZone]
at ProxyZoneSpec.onInvoke (webpack:///~/zone.js/dist/proxy.js:79:0 <- config/spec-bundle.js:70169:39) [ProxyZone]
at Zone.run (webpack:///~/zone.js/dist/zone.js:125:0 <- config/spec-bundle.js:70398:43) [<root> => ProxyZone]
at Object.<anonymous> (webpack:///~/zone.js/dist/jasmine-patch.js:104:0 <- config/spec-bundle.js:69883:34) [<root>]
TypeError: Cannot read property 'title' of undefined
at Object.<anonymous> (webpack:///src/app/home/home.component.spec.ts:54:0 <- config/spec-bundle.js:73459:22)
at ZoneDelegate.invoke (webpack:///~/zone.js/dist/zone.js:365:0 <- config/spec-bundle.js:70638:26)
at ProxyZoneSpec.onInvoke (webpack:///~/zone.js/dist/proxy.js:79:0 <- config/spec-bundle.js:70169:39)
at ZoneDelegate.invoke (webpack:///~/zone.js/dist/zone.js:364:0 <- config/spec-bundle.js:70637:32)
at Zone.run (webpack:///~/zone.js/dist/zone.js:125:0 <- config/spec-bundle.js:70398:43)
at Object.<anonymous> (webpack:///~/zone.js/dist/jasmine-patch.js:104:0 <- config/spec-bundle.js:69883:34)
I have left out more errors as they are all similar for each spec file: https://github.com/Nava2/angular-starter/tree/master/src/app. The full log output is available in this gist.
Here is the WebStorm tree:
If I remove the isolated test, there is no more errors with Angular2 tests.
Reproducible steps:
- Clone this fork: https://github.com/Nava2/angular-starter
- Run,
npm install
- Run,
npm run test
If I remove app/model/entity.no-testbed.spec.ts
, the errors disappear. I'm unsure why they are happening. If this is not the way I should develop this, please let me know as I don't want to waste time down a "poorly practiced path."
Misc Information
- OS: Windows 10
- Node Version: v8.1.2