Angular css类的绑定测试

Angular css类的绑定测试,angular,unit-testing,Angular,Unit Testing,我有一个包含加载、错误显示和实际内容的包装器。根据一些输入,我想显示一个或另一个 我想测试如果出现任何错误,是否添加了一个“中心持有者”类 组成部分: @组件({ 选择器:“sd ui状态包装器”, templateUrl:'./ui状态包装器.component.html', 样式URL:['./ui状态包装器.component.scss'], changeDetection:ChangeDetectionStrategy.OnPush, }) 导出类UIStateWrapperCompon

我有一个包含加载、错误显示和实际内容的包装器。根据一些输入,我想显示一个或另一个

我想测试如果出现任何错误,是否添加了一个“中心持有者”类

组成部分:

@组件({
选择器:“sd ui状态包装器”,
templateUrl:'./ui状态包装器.component.html',
样式URL:['./ui状态包装器.component.scss'],
changeDetection:ChangeDetectionStrategy.OnPush,
})
导出类UIStateWrapperComponent实现OnChanges{
@Input()isLoading:布尔值;
@Input()错误:字符串[]|未定义;
@HostBinding('class.centered\uu holder')centeredCss:boolean=false;
[...]
ngOnChanges():void{
this.centeredCss=this.isload | | this.errors!==undefined&&this.errors.length>0;
}
}
测试:

beforeach(异步(()=>{
TestBed.configureTestingModule({
声明:[UIStateWrapperComponent],
})
.compileComponents();
}));
在每个之前(()=>{
fixture=TestBed.createComponent(UIStateWrapperComponent);
组件=fixture.componentInstance;
component.errors=errorMock;
fixture.detectChanges();
}));
它('应该添加居中的持有者类',异步(完成)=>{
组件。ngOnChanges();
fixture.whenStable()
.然后(()=>{
log(fixture.debugElement.classes.centered\uuuuuu holder);
console.log(component.centeredCss);
expect(fixture.debugElement.classes.centered\uuuu holder)
.托贝特鲁斯();
完成();
});
});
但控制台显示:正确,错误 我还尝试了fixture.whenRenderingDone()


如何等待应用HostBinding类?

fixture.nativeElement.classList.contains('centered_uholder')应该是您需要的。还有更多关于夹具以及其他绑定属性的信息