I am using the visrtual scroll strategy in my project, but in my unit tests I use this structure for research all tags on my html list
let elements: DebugElement[] = fixture.debugElement.queryAll(By.css('span'));
expect('Today').toBe(elements[0].nativeElement.textContent);
this is my html structure:
<cdk-virtual-scroll-viewport [itemSize]="50" [minBufferPx]="buffer" [maxBufferPx]="buffer * 1.5" cass="fullHeight" >
<div #firstChild class="content">
<div *cdkVirtualFor="let demandaAgrupada of demandasAgrupadas; templateCacheSize: 1000" >
<span *ngIf="demandaAgrupada.exibeCabecalho">{demandaAgrupada.grupoPeriodo}}/span>
<pd-demanda-agrupada [demandaAgrupada]="demandaAgrupada" ></pd-demanda-grupada>
</div>
</div>
</cdk-virtual-scroll-viewport>
When i use *ngFor instead of *cdkVirtualFor, my test works.
But if I use *cdkVirtualFor, all content of my list isen't binding
and the div of *cdkVirtualFor, isen't binding too
this is my last element binding
<!--bindings={↵ "ng-reflect-cdk-virtual-for-of": "[object Object],[object Object",↵ "ng-reflect-cdk-virtual-for-template-cache-size": "1000"↵}-->
there is a bug on unit tests with *cdkVirtualFor ?
sorry about my english, is not my first language
Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.
@Jonas-Ceolin-Alberton Were you able to fix the issue?
Hi @acutexyz , not yet.
@Jonas-Ceolin-Alberton I managed to make my case work, see this: https://stackoverflow.com/questions/53726484/angular-material-virtual-scroll-not-rendering-items-in-unit-tests/53748915#53748915
Maybe a bit late, but @acutexyz solution was not working for me i solved this with:
it("should render data from hypercube", fakeAsync(() => {
...
fixture.autoDetectChanges();
flush(); /* thats make it work */
const listElements = fixture.debugElement.queryAll(By.css("div.lui-list__item"));
expect(listElements.length).toBe(2);
}));
Workss for me!, thanks @r-hannuschka
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Maybe a bit late, but @acutexyz solution was not working for me i solved this with: