I am trying to test a method that launch a modal, has anybody done this before, can someone perhaps point me in the right direction?? I have written the following test suite.
describe('bdb modal provider test suite', () => {
let bdbModal: BdbModalProvider;
let modal: Modal;
let modalCtrl: ModalController;
beforeEach(() => {
    TestBed.configureTestingModule({
        providers: [
            BdbModalProvider,
            { provide: ModalController, useClass: ModalControllerMock }
        ]
    });
    bdbModal = TestBed.get(BdbModalProvider);
    modalCtrl = TestBed.get(ModalController);
});
beforeEach(() => {
    modal = modalCtrl.create('ModalErrorPage', {});
});
it('should launch error modal', () => {
    spyOn(modal, 'present');
    bdbModal.launchErrModal('testing', 'error modal', 'OK');
    expect(modal.present).toHaveBeenCalled();
});
});
this is the error log:
should launch error modal bdb modal provider test suite Expected spy present to have been called. at UserContext. (webpack:///src/providers/bdb-modal/bdb-modal.spec.ts:31:30 <- test-config/karma-test-shim.js:140545:31)
    modalSpy = jasmine.createSpyObj('Modal', ['present']);
    modalCtrlSpy = jasmine.createSpyObj('ModalController', ['create']);
    modalCtrlSpy.create.and.callFake(function () {
        return modalSpy;
    });
TestBed.configureTestingModule({
      declarations: [
        ..............
      ],
      providers: [
        ..............
        {
          provide: ModalController,
          useValue: modalCtrlSpy
        }
        ..............
      ],
      imports: [
        ............
      ]
    }).compileComponents();
  }));
it('#display() should display modal', () => {
    .........
    expect(modalSpy.present).toHaveBeenCalled(); 
    .........
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With