Modal unit testing is not working in Ionic 2


I managed to setup a few unit tests already, but struggle with testing a Modal.
The modal shows properly from the app itself.
When running the test I receive this error:

this.addPhotoModal.present is not a function

I created this mock similarly to how I test the NavController:

export class ModalMock {

    public present(): any {
        return new Promise(function (resolve: Function): void {

and use it as a provider in my test like this:

    provide: Modal,
    useClass: ModalMock

Any feedback would be appreciated.

There’s not much to go on here, what does the rest of your test look like?

Hi Josh,

This is the whole test case:

it('should display the Add photo modal when the button is clicked and logged in', () => {

    let pub = {
        phone: '123123'
    } = pub;
    let authService = fixture.debugElement.injector.get(AuthService);



    let modal = fixture.debugElement.injector.get(Modal);
    spyOn(modal, 'present');
    debugElementArray = helper.getAllByCss(fixture, 'ion-col button');

    debugElementArray[0].triggerEventHandler('click', null);