javascript - Unit test Angular UI Bootstrap Modal -


i new angular , jasmine unit testing , trying test modal open close controller below, have tried writing unit test inject modal dont know how test methods inside. need guidance

controller:

app.controller('feeddetailscontroller', function($scope, $modal, $log, feeddealservice) {     var modalcontroller = function($scope, $modalinstance) {         $scope.cancel = function() {             $modalinstance.dismiss('cancel');         };     };      /**      * displays feed details modal      *      * @param object currentpub      */     $scope.showform = function(currentpub) {          $scope.currentpub = currentpub;          $modal.open({             templateurl: '/feeddetails/_feeddetails.html',             controller: modalcontroller,             scope: $scope,             windowclass: 'tm-modal feed-details-dialog',             resolve: {                 feeddealmodal: function() {                     $scope.modal = {                         title: 'feed details',                         headers: {                             col1: 'col1',                             col2: 'col2',                             col3: 'col3',                             col4: 'col4'                         },                         feeddeals: feeddealservice.getdeals(currentpub),                         hascancel: true,                         hassubmit: false                     };                     $scope.setdealaccess = function(dealid) {                         feeddealservice.updatedeal($scope.publishers, currentpub, dealid);                     };                     return $scope.feeddealmodal;                 }             }         });     }; }); 

test:

describe('feeddetailscontroller', function() {      beforeeach(module('premiuminventoryapp'));      var mainctrl, scope;      var fakemodal = {         result: {             then: function(confirmcallback, cancelcallback) {                 //store callbacks later when user clicks on ok or cancel button of dialog                 this.confirmcallback = confirmcallback;                 this.cancelcallback = cancelcallback;             }         },         close: function( item ) {             //the user clicked ok on modal dialog, call stored confirm callback selected item             this.result.confirmcallback( item );         },         dismiss: function( type ) {             //the user clicked cancel on modal dialog, call stored cancel callback             this.result.cancelcallback( type );         }     };      beforeeach(inject(function($modal) {         spyon($modal, 'open').and.returnvalue(fakemodal);     }));      // initialize controller , mock scope     beforeeach(inject(function ($controller, $rootscope, _$modal_) {         scope = $rootscope.$new();         mainctrl = $controller('feeddetailscontroller', {             $scope: scope,             $modal: _$modal_         });     }));      it('should open modal', function ()           // mock out modal closing, resolving selected item, 1         scope.showform(); // open modal         scope.modalinstance.close();         expect(scope.showform).toequal(fakemodal);     }); }); 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -