Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value for 'dataSource': 'undefined'. Current value: '[object Object]'.
In my component.ts I am getting this error. due to having code in ngafterviewinit.
ngAfterViewInit(): void {
this.role = this.aut.getuser();
if (this.role === undefined) {
this.router.navigate(['/']);
}
this.ELEMENT_DATA_RED_MALE = this.resul.fetchresults('red', 'male');
this.dataSourceRedMale = this.ELEMENT_DATA_RED_MALE;
this.ELEMENT_DATA_RED_FEMALE = this.resul.fetchresults('red', 'female');
this.dataSourceRedFemale = this.ELEMENT_DATA_RED_FEMALE;
this.ELEMENT_DATA_YELLOW_MALE = this.resul.fetchresults('yellow', 'male');
this.dataSourceYellowMale = this.ELEMENT_DATA_YELLOW_MALE;
this.ELEMENT_DATA_YELLOW_FEMALE = this.resul.fetchresults('yellow', 'female');
this.dataSourceYellowFemale = this.ELEMENT_DATA_YELLOW_FEMALE;
this.ELEMENT_DATA_BLUE_MALE = this.resul.fetchresults('blue', 'male');
this.dataSourceBlueMale = this.ELEMENT_DATA_BLUE_MALE;
this.ELEMENT_DATA_BLUE_FEMALE = this.resul.fetchresults('blue', 'female');
this.dataSourceBlueFemale = this.ELEMENT_DATA_BLUE_FEMALE;
this.ELEMENT_DATA_GREEN_MALE = this.resul.fetchresults('green', 'male');
this.dataSourceGreenMale = this.ELEMENT_DATA_GREEN_MALE;
this.ELEMENT_DATA_GREEN_FEMALE = this.resul.fetchresults('green', 'female');
this.dataSourceGreenFemale = this.ELEMENT_DATA_GREEN_FEMALE;
}
Please guide me about testing ngAfterviewInit, I am new to jasmine karma test.