2017-03-17 67 views
-1

我folowed官方文檔,但我仍然得到一些錯誤,有些元素似乎爲空。如何測試angular2組件與注入服務

enter image description here enter image description here

//test 

it('should welcome the user',() => { 
    fixture.detectChanges(); 
    //constcontentel.textContent; 
    expect(el.textContent).toContain('Welcome', '"Welcome ..."'); 
    expect(el.textContent).toContain('Test User', 'expected name'); 
}); 
+0

請不要添加代碼作爲屏幕截圖。如果您希望人們幫助您,請花時間幫助他們,方法是提供_格式正確且可讀的代碼_以節省時間來重現問題並幫助您解決問題。 –

回答

0

溶液調用從組件的實例方法測試

comp.NameOfMethod的內部();