2017-08-04 3 views
1

私はユーザーがページのメニューオプションを選択するとすぐに開くモーダルを持っています。私がいるIsueは、私はそれが私のngOnInit角度2 - ジャスミンテスト - ページ上にモーダルを開く

test.component.ts

constructor(public dialog: MdDialog) { } 

ngOnInit() { 
    this.openTestModal(); 
} 

openTestModal() { 
    this.dialog.open(TestModalComponent, { 
     disableClose: true, 
     width: '600px' 
    }); 
} 

で私の関数呼び出しを呼び出すために取得する方法については考えている私は私のモデルコンポーネントをインポートして試してみましたということです:

変更password.component.spec.ts

import { TestModalComponent } from '../test-modal/test-modal.component'; 
    spyOn(component, 'openTestModal'); 
    spyOn(component, 'ngOnInit').and.callThrough(); 

    it('should be created',() => { 
     expect(component).toBeTruthy(); 
    }); 

エラー

TestComponentのコンポーネントファクトリが見つかりませんでした。 @ NgModule.entryComponentsに に追加しましたか?

が、その既に存在

答えて

1

で、これはentryComponentsとテストの終了時にモジュールにごTestComponentを追加し解決するために。

@NgModule({ 
    declarations: [TestComponent], 
    entryComponents: [ 
    TestComponent, 
    ], 
}) 
class TestModule {} 

testBedインポートにTestModuleを追加します。

関連する問題