lundi 23 mars 2015

How to test $stateChangeSuccess in angular?

I just started using tests and I am a bit stuck with following code:



angular.module('ngFoobar', [])

.config(function myAppConfig($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
})

.run(function run() {})

.controller('AppCtrl', function AppCtrl($scope) {
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
if (angular.isDefined(toState.data.pageTitle)) {
$scope.pageTitle = toState.data.pageTitle + ' | Foobar';
}
});
});


This basically sets:



<title ng-bind="pageTitle"></title>


for every state change. How can I test this? I started with:



describe('AppCtrl', function() {

beforeEach(module('ngFoobar'));

var $controller, $rootScope;

beforeEach(inject(function(_$controller_, _$rootScope_) {
$controller = _$controller_;
$rootScope = _$rootScope_;
}));

describe('isCurrentUrl', function() {

var $controller, $scope;

beforeEach(function() {
$scope = {};
controller = $controller('AppCtrl', { $scope: $scope });
});
});
});


Any ideas how I can continue this? I am using jasmine 2.


Aucun commentaire:

Enregistrer un commentaire