Currently, I am working on a unit test within Angular where I need to evaluate the functionality of the save button. My goal is to have the 'save' option automatically selected when the user clicks on the button, and then proceed to execute the subsequent lines of code.
beforeEach(async () => {
fixture = TestBed.createComponent(component);
component = fixture.componentInstance;
fixture.detectChanges();
component.isPrivate = true;
component.qtsval= 7.0;
component.changeval= "";
await component.save();
//let ConfirmationDialogService = fixture.debugElement.injector.get(ConfirmationDialogComponent);
spyOn(window,'confirm').and.returnValue(true);
var displayValuationChangeDriverWarning = component.displayValuationChangeDriverWarning;
expect(displayValuationChangeDriverWarning).toBeTruthy();
component.isPrivate = true;
component.qtsval= 4.0;
});
I tried using "spyOn(window,'confirm').and.returnValue(true);" but unfortunately, it did not solve my issue. Any suggestions on how to address this problem would be greatly appreciated.
The popup window I am dealing with looks like this:
this.confirmationDialogService
.confirm(
this._messageService.areYouSure,
this._messageService.wouldYouSave,
this._messageService.save,
this._messageService.cancel,
true,
false
)
.then(async confirmed => {});