Unit testing a modalInstance controller with Karma / Jasmine

后端 未结 3 1989
故里飘歌
故里飘歌 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:11

    +1 for fiznool's answer. it is correct and should be chosen..

    I would like to note one thing though, it is not maintainable the way it is presented here.

    Since this is angular, I suggest use it..

    angular.module('...').service('$modalInstance', function(){
       ... define spies and such 
    })
    

    would make your code much more modular and generic. simply add a file under spec somewhere with the above content and make sure to include it in your karma.conf

    if you want to make sure it loads only in specific tests, simply give it a unique module name and add it to module invocation in beforeEach

提交回复
热议问题