describe('some test',function(){var$httpBackend,scope,modalServiceMock,modalInstance,someController;beforeEach(function(){inject(function(_$httpBackend_,$rootScope,$controller){$httpBackend=_$httpBackend_;scope=$rootScope.$new();// mock modal servicemodalServiceMock={showModal:function(options){return{then:function(callback){modalInstance={scope:{},close:{then:function(callback){this.callback=callback;}}};callback(modalInstance);}};}};someController=$controller('controllerName',{$scope:scope,ModalService:modalServiceMock});});it('open and close modal',function(){scope.methodInitingModal();// some checks here modal is showedmodalInstance.close.callback('confirm');// make any check modal close callback has been called with passed result string});});
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: alllx
I made a mock of ModalService for test:
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: dwmkerr
Looks great @alllx thanks for sharing this, I'll use this as a base when I write up the unit testing samples!