Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I've written tests for an AngularJS application's routes before. For instance, here's part of one I wrote:

describe('Routes', function () {

    it('should map default route to home controller', function () {
        module('myapp');
        inject(function ($route) {
            expect($route.routes['/'].controller).toBe('HomeCtrl');
            expect($route.routes['/'].templateUrl).toEqual('/static/templates/home.html');
        });
    }); 
});

However, I'm currently working on an Ionic app, and it uses the ui-router from angular-ui, rather than Angular's default routes, so it uses $state rather than $route.

My question is, is there a similar way I can test using $state? I couldn't find anything likely-sounding in the documentation

share|improve this question
    
Examine thi4s object in debugger $state.$current.self It has properties controller, template, name, url if they defined for this state – Kirill Slatin Aug 5 at 9:03
    
Hmm, I can get at $state in the debugger, but calling $state.go() in the test doesn't seem to do anything. I figure I may be missing something. – Matthew Daly Aug 5 at 9:50
    
in tests you need to call a digest cycle manually to make things happen. At $scope. or $rootScope. call $apply() or $digest(); – Kirill Slatin Aug 5 at 17:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.