I am new to testing world and I have just started writing unit tests for an existing Angular 2 code. I have a function confirmDelete
which returns Obserable&l
I've built off of peeskillet's answer. The p-confirmDialog component calls the subscribe of the service, so I had to added requireConfirmationSource, which I found in the PrimeNg source. My mock is as follows:
//
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
//
export class ConfirmationServiceMock {
public key: string = 'mock1';
public header: string = 'Delete Confirmation';
public icon: string = '';
public message: string = '';
// Call Accept to emulate a user accepting
public accept: Function;
// Call Reject to emulate a user rejecting
public reject: Function;
private requireConfirmationSource = new Subject();
requireConfirmation$ = this.requireConfirmationSource.asObservable();
//
public confirm(config: any) {
console.log( 'In confirm service mock...' );
this.message = config.message;
this.accept = config.accept;
this.reject = config.reject;
console.log( this.message );
return this;
}
}
//