我有一个模板驱动的表单,其中包含许多输入,如下所示
<input type="text" name="data" [(ngModel)]="data" [disabled]="disabled" />
我想编写一个测试,确保在disabled
变量设置为true时禁用所有输入。以下是我到目前为止的测试。它有效,但有几个&#34;禁用&#34; element
和element.nativeElement
上的属性仍为false。此外,在调试器中停止时,Chrome中呈现的视图看起来不会被禁用。只有&#34; ng-reflect-is-disabled&#34;属性实际上是真的。
it("should disable all inputs when disabled is true", () => {
component.disabled = true;
fixture.detectChanges();
inputs = fixture.debugElement.queryAll(By.css('input'));
inputs.forEach(element => {
expect(element.attributes["ng-reflect-is-disabled"]).toBe('true');
});
});
有没有更好的方法可以实际检查输入的禁用状态?