Swetha
Swetha

Reputation: 1079

How to write jasmine unit test for primeng datatables?

Could any one of you help me out on how to write unit test for (onRowSelect) event of primeng datatable. In my scenario i am trying to navigate to another component when user clicked on row.

Upvotes: 1

Views: 4808

Answers (1)

Julia Passynkova
Julia Passynkova

Reputation: 17879

Here is how I do unit testing for onRowClick with PromeNG datatable. It should be very similar to onRowSelect.

You can look at component and its unit test at my github repo: 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();
  });
}));

Upvotes: 4

Related Questions