角度/茉莉花:类型错误:无法读取未定义的角度的属性'labels'



我为组件编写单位角度。当我运行测试时,终端显示了一个错误。TypeError:无法读取未定义的属性"labels"当我运行测试用例时,有3个功能错误

private checkRating(): boolean {
if ((Object.keys(this.ratingData.labels).length) > 0) {
return true;
} else {
return false;
}
}
ngAfterContentChecked(): void {
this.handlerBallonBar();
}
private handlerBallonBar() {
return this.ratingOptions = {
title: {
display: false
},
legend: {
position: 'right',
display: false
},
scales: {
xAxes: [
{
ticks: {
beginAtZero: true,
},
display: false,
}
],
yAxes: [
{ display: this.checkRating() }
]
},
responsive: true,
plugins: {
datalabels: {
labels: {
value: {
color: '#ffffff'
}
},
font: {
size: '12'
}
}
}
}
}

这是一个定义测试用例

describe('BalloonComponent', () => {
let component: BalloonComponent;
let fixture: ComponentFixture<BalloonComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BalloonComponent]
}).overrideTemplate(BalloonComponent, '');
}));
beforeEach(() => {
fixture = TestBed.createComponent(BalloonComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy()
});

这是错误在此处输入图像描述

你能更新下面的代码吗

private checkRating(): boolean {
if (this.ratingData && this.ratingData.labels && (Object.keys(this.ratingData.labels).length) > 0) {
return true;
} else {
return false;
}
}

最新更新