如何测试md-select中的选定选项

时间:2018-02-02 11:34:27

标签: angular testing karma-jasmine

我想在视图测试中测试可用选项,但我在md-select中看不到所选的选项,我看到placeHolder文字。 测试的错误消息如“Expected 'Country ' to be 'Turkey', 'selected country must be loaded correctly in 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">
    {{ country.name}}
  </md-option>
</md-select>

试验:

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


}))

0 个答案:

没有答案