I am getting ExpressionChangedAfterItHasBeenCheckedError
with a getter and BehaviorSubject (fun, right?).
Here is the code in the component
private _windowHeight: string = '';
constructor( private stepService: StepService, private commonService: CommonService ) {
this.commonService.windowHeight.subscribe( ( height: number ) => {
this._windowHeight = height + 'px';
} );
}
@HostBinding( 'style.min-height' )
public get windowHeight(): string {
return this._windowHeight;
}
commonService.windowHeight
is a BehaviorSubject. All is fine and well when running this code in a normal browser.
My problem arises when I try to run unit tests with the component. All imports, declarations and providers are fine, and still with a simple test like this
it( 'should create', () => {
expect( component ).toBeTruthy();
} );
it throws the Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '0px'. Current value: '865px'.
What could be the issue here? The environment: Angular 4.0.2, Angular CLI, karma, headless Chrome.
Thanks!