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.
appcontroller :
$rootscope.setuser = function() {}
authenticationcontroller
$rootscope.setuser();
Comments
Post a Comment