Components: cdkVirtualFor don't binding the content of my list in unit tests

Created on 29 Nov 2018  Â·  7Comments  Â·  Source: angular/components

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

Most helpful comment

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);
    }));

All 7 comments

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.

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julianobrasil picture julianobrasil  Â·  3Comments

jelbourn picture jelbourn  Â·  3Comments

savaryt picture savaryt  Â·  3Comments

shlomiassaf picture shlomiassaf  Â·  3Comments

michaelb-01 picture michaelb-01  Â·  3Comments