Skip to content

Instantly share code, notes, and snippets.

@masimplo
Created June 30, 2017 09:36
Show Gist options
  • Save masimplo/156160c1bec2ad45e68b552323b9881e to your computer and use it in GitHub Desktop.
Save masimplo/156160c1bec2ad45e68b552323b9881e to your computer and use it in GitHub Desktop.
Testing presentables
const modal = this._modal.create(CommunicationAddNoteModalComponent);
modal.onDidDismiss((data: { note: string }) => {
this.note = data.note;
});
modal.present();
export class PresentableControllerMock {
public presentableRef = {
present: () => Promise.resolve(),
dismiss: (data?: any) => {
if (this.dismissCallbackFn) {
this.dismissCallbackFn(data);
}
return Promise.resolve({});
},
onDidDismiss: (fn) => {
this.dismissCallbackFn = fn;
}
};
public dismissCallbackFn = null;
public create(options?) {
return Object.assign(this.presentableRef, options);
}
}
it('updates the contact note if it is edited', function () {
const modalCtrl = fixture.debugElement.injector.get(ModalController);
spyOn(modalCtrl, 'create').and.callThrough();
const modal = (<PresentableControllerMock>(<any>modalCtrl)).presentableRef;
spyOn(modal, 'present').and.callThrough();
sut.method();
expect(modal.present).toHaveBeenCalled();
modal.dismiss({ note: 'new note' });
expect(sut.notes).toEqual('new note');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment