javascript - AngularJS Testing with Jasmine and Karma -


i try test angular controller returns promise , cant resolve it...what's wrong code?

the angular controller:

kpi.aboutcontroller = function ($scope, version) {      function loadversion() {         //$scope.version = version.getversion();         $scope.version = '1.1.0';     }      loadversion(); }; 

and jasmine test:

describe('dashboard: aboutcontroller', function() { beforeeach(module('dashboard')); var $controller; beforeeach(inject(function(_$controller_){     // injector unwraps underscores (_) around parameter names when matching     $controller = _$controller_; })); it('testing version number', function() {     var $scope = {};     var controller = $controller('aboutcontroller', { $scope: $scope });     var version = 0;     console.log($scope.version);     expect($scope.version).tocontain("1."); }); }); 

this working, when change line $scope.version = '1.1.0'; $scope.version = version.getversion(); receive promise , can not rly check it....i tried resolve "then()" function via $scope.version.then(...)but did not work...what do?

edit:

the following error occures:

expected e({ $promise: object({ $$state: object({ status: 0 }) }), $resolved: false }) contain '1.'.     @ object.<anonymous> 

and service:

kpi.versionfactory = function ($resource, appconfig) { var version = $resource(thepath, {}, {      "getversion": {         method: "get",         url: thepath,         isarray: false     }  });  return version; }; 

you need pass callback test case .

kpi.aboutkpicontroller = function ($scope, version) {      $scope.loadversion= function () {       version.getversion().then(function(res){                    $scope.version = res.data;             })     }       $scope.loadversion(); }; describe('dashboard: aboutkpicontroller', function() {   beforeeach(module('dashboard'));   var $controller;   beforeeach(inject(function(_$controller_){     // injector unwraps underscores (_) around parameter                names when matching     $controller = _$controller_;  }));  it('testing version number', function(done) {     var $scope = {};     var controller = $controller('aboutkpicontroller', { $scope: $scope });     var version = 0;     console.log($scope.version);     $scope.loadversion().then(function(res)){              //can test here              expect($scope.version).tocontain("1.");             done();       });      }); 

});


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -