0

I am trying to test the routes defined for the angular-ui-router of my AngularJS application. The test is using a karma / jasmine setup. I am injecting the $state service in the test in order to check if all relevant states have been defined. However, the $state service only lists a single (empty) state. Here is how the module setup and the test setup look like:

Module Definition:

angular.module('module', ['ui.router'])

.config(function($stateProvider) {

    $stateProvider
        .state('state01', {
            url: '/state01'
        })
        .state('state02', {
            url: '/state02'
        });
});

Test Definition:

describe('module', function() {
    var $state;

    beforeEach(module('module'));

    beforeEach(inject(function (_$state_) {
        $state = _$state_;
    }));

    describe('module config', function() {
        it('should test stuff...', function() {
            console.log($state.get());
            // prints: [Object{name: '', url: '^', views: null, abstract: true}]
        });
    });
});

Any ideas, why the $state service might be missing the router state definitions?

4
  • are you sure you have v0.3.0 of ui-router? Commented Sep 28, 2015 at 12:54
  • I am using v0.2.15 of ui.router. Isn't this the most recent one? Commented Sep 28, 2015 at 13:49
  • please do look at API page github.com/angular-ui/ui-router/wiki/… Commented Sep 28, 2015 at 14:21
  • Ah, I see. As far as I can tell, the get() call should work in v0.2.15 (github.com/angular-ui/ui-router/blob/0.2.15/src/state.js#L1375). What would be an alternative approach? Commented Sep 28, 2015 at 14:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.