I have a simple function in my main controller that updates $scope.loading based on ui.router's $stateChangeStart and $stateChangeSuccess events.
$scope.$on('$stateChangeStart', function(event, toState) {
if (toState.resolve) {
$scope.loading = true;
}
});
$scope.$on('$stateChangeSuccess', function(event, toState) {
if (toState.resolve) {
$scope.loading = false;
}
});
This works great until I try to unit test. I can't find a way to trigger the $stateChangeSuccess event.
My Jasmine unit test looks something like this:
it('should set $scope.loading to true', function () {
expect(scope.loading).toBe(false);
$state.go('home');
expect(scope.loading).toBe(true);
scope.$digest();
expect(scope.loading).toBe(false);
});
The test fails because $stateChangeSuccess never fires. Any ideas would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire