2017-06-29 11 views
1

モデルを作成してAngular 2アプリをバックしようとしています。私はAngular2を初めて使っています。カルマとアンギュラ2 - 孤立テストと非孤立テストを混在させるとランタイムインジェクションが失敗する

モデルは、旧式のJavaコードベースからTypeScriptに移動するポートです。その際、"isolated" testと分類されるテストを作り直しています。

問題:

は、単離されたテストを追加した後、シードから全て Angular2試験はカルマに同様のエラーで失敗:彼らがすべて類似しているように、私はより多くのエラーを残している

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) 

各スペックファイル:https://github.com/Nava2/angular-starter/tree/master/src/app。フルログ出力はthis gistで利用できます。ここで

はWebStormの木である:

WebStorm Test Tree

私は孤立し、テストを削除する場合は、Angular2テストとは多くの誤りがありません。

再現手順:

  1. クローンこのフォーク:https://github.com/Nava2/angular-starter
  2. を実行し、npm install
  3. を実行し、npm run test

私はapp/model/entity.no-testbed.spec.tsを削除すると、エラーが消えます。なぜ彼らが起きているのか分かりません。これが私がこれを発展させるべき方法でないなら、私は「練習道が貧弱」という時間を無駄にしたくないので教えてください。

その他の情報

  • OS:Windowsの10
  • ノードのバージョン:V8.1.2

答えて

0

それはあなたのspecファイルのソースコードを見るために役立つだろう。まだHomeComponentをインポートしていないようです。

+0

いいえ、そうではありません。 specファイルはhttps://github.com/Nava2/angular-starter/tree/master/src/appにあります。 – Nava2

関連する問題