In my unit test I want to call openDialog
, openPdf
, getPath
with these three eventemitter that are in the ngOnDestroy
method. How can I call them?
component.ts
:
pdfPath: string = ''; // will be edited later
@Output() openDialog = new EventEmitter();
@Output() openPdf = new EventEmitter();
@Output() getPath: EventEmitter<string> = new EventEmitter();
getData() {
// ...
this.openDialog.emit(true);
}
showData() {
// ...
this.openPdf.emit();
}
fetchData() {
// ...
this.getPath.emit(this.pdfPath);
}
ngOnDestroy(): void {
this.openDialog.unsubscribe();
this.openPdf.unsubscribe();
this.getPath.unsubscribe();
}
I've tried calling them like this in the beforeEach
and use spyOn(component.openDialog, 'subscribe');
, but this isn't working:
const emitter = new EventEmitter();
component.openDialog = emitter;
component.openPdf = emitter;
component.getPath = emitter;
emitter.emit(true);