Angular 角度材料:测试线束-如何检查输入是否具有等级';ng肮脏';?

Angular 角度材料:测试线束-如何检查输入是否具有等级';ng肮脏';?,angular,angular-material,automated-tests,Angular,Angular Material,Automated Tests,使用,我们应该基于PageObject结构开发测试,该结构提供了我们应该知道的关于该元素的所有信息 我有一个测试,我需要检查输入是否脏。如何正确使用组件线束来实现这一点?我知道我可以访问元素并获得类,但它看起来并不正确。有什么反应吗 组成部分: 从'@angular/core'导入{Component}; 从'@angular/forms'导入{FormControl}; @组成部分({ 选择器:“sdx输入线束”, 模板:` ` }) 导出类InputHarnessComponent{ pub

使用,我们应该基于PageObject结构开发测试,该结构提供了我们应该知道的关于该元素的所有信息

我有一个测试,我需要检查输入是否脏。如何正确使用组件线束来实现这一点?我知道我可以访问元素并获得类,但它看起来并不正确。有什么反应吗

组成部分:

从'@angular/core'导入{Component};
从'@angular/forms'导入{FormControl};
@组成部分({
选择器:“sdx输入线束”,
模板:`
`
})
导出类InputHarnessComponent{
public-formControl:formControl=new-formControl();
}
组件测试:

从'@angular/core/testing'导入{ComponentFixture,TestBed};
从“@angular/cdk/testing”导入{HarnessLoader};
从“@angular/cdk/testing/testbed”导入{testbedlunnevironment};
从“@angular/material/input/testing”导入{MatInputHarness};
从“./input harness.component”导入{InputHarnessComponent};
从'@angular/forms'导入{ReactiveFormsModule};
从“@angular/material/form field”导入{MatFormFieldModule};
从“@angular/material/input”导入{MatInputModule};
从“@angular/platform browser/animations”导入{NoopAnimationsModule};
描述('InputHarnessComponent',()=>{
let组件:InputArnessComponent;
let夹具:组件夹具;
let loader:Harness loader;
beforeach(异步()=>{
等待TestBed.configureTestingModule({
声明:[InputHarnessComponent],
导入:[ReactiveFormsModule、MatInputModule、MatFormFieldModule、NoopAnimationsModule]
})
.compileComponents();
});
在每个之前(()=>{
fixture=TestBed.createComponent(InputHarnessComponent);
组件=fixture.componentInstance;
加载器=测试床线束环境。加载器(夹具);
fixture.detectChanges();
});
fit('should create',async()=>{
const input=await loader.getHarness(MatInputHarness.with({selector:'#name'}));
等待输入。focus();
等待输入。设置值(“新值”);
等待fixture.detectChanges();
const com=fixture.nativeElement;
//管用!但听起来不太对劲---------------------------------
const host=wait input.host();
const className=wait host.getAttribute('class');
expect(className.includes('ng-dirty')).toBe(true);
});
});

这是我第一次看到
TestBedHandlenEnvironment
,但我会将最后3行更改为:

const inputAfterChange = fixture.debugElement.query(By.css('#name.ng-dirty'));
expect(inputAfterChange).toBeTruthy();
我们使用CSS选择器“#name.ng dirty”查询dom中的元素,并确保它存在