angularjs - How to stub out a controller method called during object construction -


i have angularjs controller calls own refresh() method while being constructed. method in question accesses template elements not present during unit testing.

function listcontroller($scope) {     /// ...      $scope.refresh = function() {         var tabid = angular.element('#id li.active a').attr('href');         //etc     }      //initialise     $scope.refresh(); } 

the refresh method causes unit tests fail while controller being constructed. work irrelevant tests, want override method stub , test has been called.

jasmine's spy functionality looks way go, can't find way of setting 1 object before constructed. how this?

you should move directive's link function. link function result of compile know sure element compiled , ready, , make "refresh" function unnecessary. in general, should never access dom via jqlite or jquery controller. also, link function provides direct access element, scope, , attributes (even href) nice.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -