mercredi 21 décembre 2016

Angular 2 unit test must call whenStable multiple times when nesting ngModel elements

I am well aware of this bug here:

http://ift.tt/2hV4hDp

Which mentions the need to call fixture.detectChanges(); then a fixture.whenStable().

However, when I start nesting elements that each makes a usage of the ngModel value accessor provider, I have to call these two methods in a loop.

Is there a different way to do this? It doesn't seem super efficient and I constantly need to edit this function. I could simplify this with a recursive method to prevent duplication, but that's not the question.

export function bugWhenStable(fixture: ComponentFixture<any>): Promise<any> {
    let def = new Promise(resolver => {
        fixture.detectChanges();
        fixture.whenStable().then(() => {
            fixture.detectChanges();
            fixture.whenStable().then(() => {
                fixture.detectChanges();
                fixture.whenStable().then(() => {
                    resolver();
                });
            });
        });
    });

    return def;
}

My components do something like this:

<wm-comp1 [(ngModel)]="value"></wm-comp1>

Which in Comp1 I have

<wm-comp2 [(ngModel)]="value"></wm-comp2>

etc.

Aucun commentaire:

Enregistrer un commentaire