Created
June 30, 2017 09:36
-
-
Save masimplo/156160c1bec2ad45e68b552323b9881e to your computer and use it in GitHub Desktop.
Testing presentables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const modal = this._modal.create(CommunicationAddNoteModalComponent); | |
modal.onDidDismiss((data: { note: string }) => { | |
this.note = data.note; | |
}); | |
modal.present(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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