Unit testing a modalInstance controller with Karma / Jasmine

后端 未结 3 1984
故里飘歌
故里飘歌 2020-12-12 18:09

EDIT : Quick & Dirty solution at the end of this post

I am using a modal window from AngularUI-Bootstrap in the same way that it is explained on

3条回答
  •  甜味超标
    2020-12-12 19:09

    Instead of:

    modalInstance = {                    // Create a mock object using spies
      close: jasmine.createSpy('modalInstance.close'),
      dismiss: jasmine.createSpy('modalInstance.dismiss'),
      result: {
        then: jasmine.createSpy('modalInstance.result.then')
      }
    };

    This can be written as:

    modalInstance = jasmine.createSpyObj('modalInstance', ['close', 'dismiss', 'result.then']);

    Also there is no $modalInstance it is now $uibModalInstance so every "modalInstance" above should be replaced with "uibModalInstance"

提交回复
热议问题