Jasmine unit test cases -


i new jasmine tests , have not able been able find solution after trying many ways. can suggest test case code in angularjs?

  modalinstance.result.then(function (modaloutput) {           if (modaloutput) {         if ('oktoundoedits' === modaloutput[1]) {           $scope.chargebackdetail.cbdetails = angular.copy($scope.chargebackdetailbackup.cbdetails);         } else if ('oktosaveunmatched' === modaloutput[1]) {           $('#nomatchwarning').show();           $scope.ismatcheddoc = false;         }       }     }, function () {     }); 

the following test assumes using angular ui bootstraps $modal. code untested, should close need started.

it('should revert chargebackdetail.cbdetails backup, if ok undo edits', inject(function($modal, $q) {   // arrange   $scope.chargebackdetail = {};   $scope.chargebackdetailbackup = {cbdetails: [11, 13, 17]};    var deferred = $q.defer();   spyon($modal, 'open').and.returnvalue({result: deferred.promise});    // act   $scope.whateveryourfunctioniscalled();    deferred.resolve([null, 'oktoundoedits']);   $scope.$apply();    // assert   expect($scope.chargebackdetail.cbdetails).toequal($scope.chargebackdetailbackup.cbdetails);   expect($scope.chargebackdetail.cbdetails).not.tobe($scope.chargebackdetailbackup.cbdetails); })); 

according comment, doing following in test:

it('should open', function() {    spyon(commonservice, 'openmodal').and.callfake(function() {      return {        // create mock object using spies        close: jasmine.createspy('modalinstance.close'),       dismiss: jasmine.createspy('modalinstance.dismiss'),       result: {          then: jasmine.createspy('modalinstance.result.then')        }      };    });    scope.open();  }); 

this tells me wrapping $modal.open() in service called commonservice.openmodal(). original test still applies, need change line:

spyon($modal, 'open').and.returnvalue({result: deferred.promise}); 

to this:

spyon(commonservice, 'openmodal').and.returnvalue({result: deferred.promise}); 

you no longer need inject $modal have done. if doesn't make sense you, should start more simple tests understand testing angular jasmine.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -