【发布时间】:2022-02-18 02:16:09
【问题描述】:
我在 html 中有这段代码,用于禁用 ngAfterViewInit() 上的下拉菜单:
<select-field
#dueBy
width="100%"
label=" "
formControlName="dueByIndex"
[options]="dueByValues"
[ngClass]="{ disableUnEditableFields: showChanges }"
></select-field>
select-field 是客户提供的自定义标签。 在组件类中:
@ViewChild('dueBy') dueBySelect;
ngAfterViewInit(): void {
if (this.showChanges) {
this.dueBySelect.control.disable();
}
我正在尝试为此编写单元测试,但由于未定义,dueBySelect 即将到来。我环顾四周,但在大多数情况下,模板引用变量是某些方法调用的目标。一种尝试如下:
it('should disable the advanced fields', () => {
component.showChanges = true; // to go inside the if condition in ts file
const dueBySelectInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#dueBy');
console.log(component.dueBySelect); // coming as undefined
请给点建议!!谢谢。
【问题讨论】:
标签: angular jestjs karma-jasmine