Html:
<checkbox (change)="onChange()" [(ngModel)]="ngModel"> Checkbox </checkbox>
ц
ngModel: boolean;
@Output() checkboxEvent = new EventEmitter<any>();
onChange() {
this.checkboxEvent.emit(this.ngModel);
}
контрольный пример:
it('TC 3: should emit an event on change of checkbox', async(() => {
spyOn(component.checkboxEvent, 'emit');
component.onChange();
const edlCheckbox = fixture.debugElement.query(By.css('checkbox ')).nativeElement;
edlCheckbox.dispatchEvent(new Event('change'));
fixture.detectChanges();
expect(component.checkboxEvent ).toHaveBeenCalled();
expect(component.checkboxEvent .emit).toHaveBeenCalledWith(true);
}));
Ошибка:
Failed: <toHaveBeenCalled> : Expected a spy, but got EventEmitter(
{ _isScalar: false, observers: [ ], closed: false,
isStopped: false, hasError: false, thrownError: null,
__isAsync: false, emit: spy on emit }).
Usage: expect(<spyObj>).toHaveBeenCalled()