angularjs - Writing Unit Test Case in Angular JS using Jasmine -


i building application using angular js. new don't know writing test cases in it.

suppose have service:

angular.module('myapp').  factory('mainpage', function($resource,base_url){  return $resource("my api call", {}, {query: {method:'get'}, isarray:true});  }). 

my controller:

var app = angular.module('myapp')  app.controller('mainctrl',function($scope,mainpage,$rootscope){ $scope.mainpage = mainpage.query();     }); 

how write test case controller in angular js using jasmine.

you write along these lines:

describe('myapp controllers', function() {    describe('mainctrl', function(){      it('should populate query', function() {       var scope = {},           ctrl = new mainctrl(scope);        expect(scope.mainpage).toequal(somemainpagemock);     });   }); }); 

this documented, see angularjs tutorial quick reference, it's suggested read jasmine docs (!).

you'd want spy on query() method, see here on how.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -