lundi 28 septembre 2015

Missing angular-ui-router states in AngularJS unit test

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?

Aucun commentaire:

Enregistrer un commentaire