I have a wrapper with a loading, an error display and the actual content. Depending on some inputs I want to show one or another.
I want to test if given any error a 'centered__holder' class is added
The component:
@Component({
selector: 'sd-ui-state-wrapper',
templateUrl: './ui-state-wrapper.component.html',
styleUrls: ['./ui-state-wrapper.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UIStateWrapperComponent implements OnChanges {
@Input() isLoading: boolean;
@Input() errors: string[] | undefined;
@HostBinding('class.centered__holder') centeredCss: boolean = false;
[...]
ngOnChanges(): void {
this.centeredCss = this.isLoading || this.errors !== undefined && this.errors.length > 0;
}
}
The test:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [UIStateWrapperComponent],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UIStateWrapperComponent);
component = fixture.componentInstance;
component.errors = errorMock;
fixture.detectChanges();
}));
it('should add centered__holder class', async (done) => {
component.ngOnChanges();
fixture.whenStable()
.then(() => {
console.log(fixture.debugElement.classes.centered__holder);
console.log(component.centeredCss);
expect(fixture.debugElement.classes.centered__holder)
.toBeTruthy();
done();
});
});
But the console shows: true, false
I've also tried with fixture.whenRenderingDone()
How can I wait for HostBinding class to be applied?