vendredi 2 février 2018

How to test selected option in md-select

I want to test available option in view test but I can not see the selected option in md-select, I see placeHolder text. Test's error message like this "Expected 'Country ' to be 'Turkey', 'selected country must be loaded correctly in view'."

view:

<md-select [ngModelOptions]="{standalone: true}" placeholder="Country" 
 style="margin-top: 6px;"
 [(ngModel)]="customer.address.country">
  <md-option *ngFor="let country of countries"
       [value]="country.code">
    
  </md-option>
</md-select>

test:

 it('customer should edit', fakeAsync(() => {

    fixture.detectChanges();
    tick();

    let countryInput = fixture.debugElement.query(By.css("md-select[placeHolder='Country']"));

    expect(countryInput.nativeElement.innerText).toBe("Turkey", "selected country must be loaded correctly in view");


}))

Aucun commentaire:

Enregistrer un commentaire