我无法在表中使用lazayload测试virtualScroll
<p-table class="basicTable" [value]="cars" [scrollable]="true" [rows]="100" scrollHeight="500px"
(onLazyLoad)="load($event)" [rows]="100" lazy="true"
[virtualScroll]="true"> const tableEl = fixture.debugElement.query(By.css('.p-datatable-virtual-scrollable-body'));
fixture.detectChanges();
const bodyRows = tableEl.query(By.css('.p-datatable-tbody')).queryAll(By.css('tr'));
console.log(bodyRows)bodyRows为空
谢谢
发布于 2021-04-30 00:58:41
Angular团队的单元测试为我提供了一个答案。在CDK Virtual Scroll显示数据之前,有许多异步步骤,所以我们必须模拟这些步骤。将以下函数添加到.spec.ts文件的顶部,并在将fixture作为参数传递时调用它,而不是fixture.detectChanges():
const finishInit = (fixture: ComponentFixture<any>) => {
// On the first cycle we render and measure the viewport.
fixture.detectChanges();
flush();
// On the second cycle we render the items.
fixture.detectChanges();
flush();
// Flush the initial fake scroll event.
tick(500);
flush();
fixture.detectChanges();
};您的it还需要使用fakeAsync
it('should display virtual scroll data', fakeAsync(() => {
}));https://stackoverflow.com/questions/66280201
复制相似问题