【发布时间】:2021-01-18 18:36:13
【问题描述】:
当样式更改为父组件时,我有这个子组件会发出 true 或 false:
export class PruebaComponent implements OnInit, OnChanges {
@Output() statusEvent = new EventEmitter<boolean>();
getSytle(): string {
return this.valueStyle;
}
private calcStyle(): void {
this.calcPopUpStyle();
if (this.isEngReady) {
this.valueStyle = 'icon-green';
this.statusEvent .emit(true);
} else {
this.valueStyle = 'icon-red';
this.statusEvent.emit(false);
}
this.ref.detectChanges();
}
}
我尝试编写测试以检查当 isEngReady 也为真时发出的 statusEvent 是否为真,我尝试了这个:
describe('PruebaComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ChatComponent]})
.compileComponents();
}));
it('should emit chat availability to true if the engagement is available', () => {
spyOn(component.statusEvent, 'emit')
component.isEngReady = true;
component.getSytle();
//expect(component.statusEvent.emit).toHaveBeenCalled();
expect(component.statusEvent.emit).toHaveBeenCalledWith(true);
});
});
但我收到此错误消息: 预期的间谍发射已被调用:[真] 但它从未被调用过。
【问题讨论】:
标签: angular typescript testing eventemitter testunit