javascript - How to test function in $scope from different controller? -


i'm using jasmine testing angularjs application. have authenticaiton controller, calls function define in scope application controller. so:

1. appcontroller

$scope.setuser = function() {} 

2. authenticationcontroller

$scope.setuser(user); 

i testing authenticationcontroller, , setuser() not inside scope of authenticationcontroller. how inject scope/function appcontroller?

the error message:

typeerror: $scope.setuser not function 

should mock whole function? structure smelly? what's best way this?

edit: in real app, authenticationcontroller gets injected dashboard-app.

authenticationcontroller:

angular   .module( 'authentication', [])   .controller('authenticationcontroller', authenticationcontroller);  authenticationcontroller.$inject = ['$scope', '$rootscope', 'auth_events', 'authenticationservice']; 

dashboard:

angular   .module('dashboard', [     'authentication'   ])   .run(run); 

info: names changed in question make easier understand.

inject $rootscope controllers.

  1. appcontroller :

    $rootscope.setuser = function() {}

  2. authenticationcontroller

    $rootscope.setuser();


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -