2017-02-20 44 views

回答

0

以下是我如何使用PromeNG數據表進行onRowClick單元測試。它應該和onRowSelect非常相似。

你可以看一下成分,並在我的github上回購其單元測試:https://github.com/ipassynk/ristorante-fornello/tree/master/src/app/menu

it('should call showDetails on row click', async(() => { 
    const spy = spyOn(comp, 'showDetails'); 
    fixture.detectChanges(); 

    const cell = debugElement.queryAll(By.css('.ui-datatable-odd .ui-cell-data'))[0]; 
    cell.nativeElement.click(); 
    fixture.detectChanges(); 

    fixture.whenStable().then(() => { 
    expect(spy).toHaveBeenCalled(); 
    }); 
}));