2017-02-23 7 views
2

現在angullar-cliでangular2プロジェクトに取り組んでいます。 tomorowから、ng testコマンドから新しいエラーが発生しました。これは以下のトレースです。このエラーは、ng testコマンドを実行するたびに発生します。私はspec.tsでコードを特定してエラーを発生させます。Angular2/ngテストエラー: 'Unhandled Promise拒否'

const fakeRouter = jasmine.createSpyObj('Router', ['navigate']); 
beforeEach(() => TestBed.configureTestingModule({ 
    imports: [AppModule, RouterTestingModule], 
    providers: [{ provide: Router, useValue: fakeRouter }] 
})); 

プロバイダのルータを削除すると、エラーは消滅します。 しかし、すべてのテストが成功しました。

マイ角度-cliのバージョン:

角度-CLI:1.0.0-beta.32.3 ノード:6.7.0 OS:Win32のx64の

ERROR:

ERROR: 'Unhandled Promise rejection:', 'Cannot set property 'afterPreactivation' of undefined', '; Zone:', 'ProxyZone', '; Task:', 'Promise.then', '; Value:', TypeError{}, 'TypeError: Cannot set property 'afterPreactivation' of undefined 
     at http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:66907:49 
     at ZoneDelegate.invoke (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94256:26) 
     at ProxyZoneSpec.onInvoke (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:70192:39) 
     at ZoneDelegate.invoke (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94255:32) 
     at Zone.run (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94052:43) 
     at http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94605:57 
     at ZoneDelegate.invokeTask (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94289:31) 
     at ProxyZoneSpec.onInvokeTask (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:70216:39) 
     at ZoneDelegate.invokeTask (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94288:36) 
     at Zone.runTask (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94092:47) 
     at drainMicroTaskQueue (http://localhost:9876/base/src/test.ts?10abbba6756b062e1f8ba4c1873d1f257bc67f65:94455:35) 
+0

解決策は見つかりましたか?私は同じ問題を抱えている。 –

答えて

0

I問題を解決する方法を見つける。私はテストでappModuleのインポートを、必要なすべてのモジュール、コンポーネント、およびサービスで置き換えます。私はappmoduleもルータモジュールをインポートするので、エラーがあると思う。

beforeEach(() => TestBed.configureTestingModule({ 
    declarations: [component1, component2, ...], 
    imports: [module1, module2, ...], 
    providers: [service1, service2, { provide: Router, useValue: fakeRouter }] 
})); 
関連する問題