1:mat-select 有 4 个值,1,2,3,4。
下面的代码适用于选择。所以如果它对读者有帮助,我想分享一下。
it('check the length of drop down', async () => {
const trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
trigger.click();
fixture.detectChanges();
await fixture.whenStable().then(() => {
const inquiryOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(inquiryOptions.length).toEqual(4);
});
});
Run Code Online (Sandbox Code Playgroud)
2:我需要另一个测试来验证同一个 mat-select 中的默认值是否为 3。当页面加载时,下拉菜单的默认值设置为 3。
it('should validate the drop down value if it is set by default', async () => {
const trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;
trigger.click();
fixture.detectChanges();
await fixture.whenStable().then(() => {
const inquiryOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
const value = trigger.options[0].value;
expect(value).toContain(3);
});
});
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。