我只是想做這個工作。Angular 2:模板在測試中沒有更新
it('should have expected <h1> text', async(() => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const sectionEl = fixture.debugElement.query(By.css("section"));
spyOn(fixture.debugElement.componentInstance, "runMe");
sectionEl.nativeElement.click();
expect(fixture.debugElement.componentInstance.runMe).toHaveBeenCalled();
expect(sectionEl.nativeElement.textContent).toBe("changed!");
所以,runMe
功能並沒有改變部分的文本,但諜顯示runMe
被調用。
你能編輯你的文章以包含你的'runMe'函數的代碼嗎? – jhhoff02