angular-ui-router testing: current state object has no actual meaning

566 views
Skip to first unread message

Mihail Zheludev

unread,
Jul 29, 2014, 1:11:02 AM7/29/14
to ang...@googlegroups.com
I use angularjs v1.2.20, angular-mock v1.2.19, ui.route v0.2.10. For the next route I can't get working test. I have one route:

angular.module('application')

.config(function ($stateProvider, $urlRouterProvider) {
   
'use strict';

   
function getTemplate(templateName) {
       
return  'modules/' + templateName + '/template.html';
   
}

    $urlRouterProvider
.
        otherwise
('/login');

    $stateProvider

       
.state('main', {
           
abstract: true,
            views
: {
               
'': {
                    templateUrl
: getTemplate('layouts/public')
               
},
               
'footer@main': {
                    templateUrl
: getTemplate('footer'),
                    controller
: 'FooterController'
               
}
           
}
       
})

       
.state('main.login', {
            url
: '/login',
            templateUrl
: getTemplate('login'),
            controller
: 'LoginController'
       
});          
   
}
);

and one test for that route:

describe('Routers', function () {
"use strict";

   
var state, rootScope;

    beforeEach
(function () {
       
module('application');
        inject
(function ($rootScope, $state) {
            rootScope
= $rootScope;
            state
= $state;
       
});
   
});

    describe
('login state', function () {

        beforeEach
(inject(function ($httpBackend) {
            $httpBackend
.expectGET('modules/layouts/public/template.html')
               
.respond(200, 'main HTML');
            $httpBackend
.expectGET('modules/footer/template.html')
               
.respond(200, 'main HTML');
            $httpBackend
.expectGET('modules/login/template.html')
               
.respond(200, 'main HTML');
       
}));

        it
('main.login state controller should be LoginController', function () {
            state
.go('main.login');
            rootScope
.$digest();
            console
.log(state.current);
            expect
(state.current.controller).toBe('LoginController')
       
});
   
})
});

but in console I see such log:

Object{name: '', url: '^', views: null, abstract: true}
Expected undefined to be 'LoginController'.
Error: Expected undefined to be 'LoginController'.

How can I test that is exactly LoginController for 'main.login' state ?

刘桂晓

unread,
Nov 25, 2014, 7:22:55 AM11/25/14
to ang...@googlegroups.com
the same question, have u solved?

在 2014年7月29日星期二UTC+8下午1时11分02秒,Mihail Zheludev写道:

Mihail Zheludev

unread,
Nov 25, 2014, 10:08:13 AM11/25/14
to ang...@googlegroups.com
No, I didn't 
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/XsLDAScnQKQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


--
Have a nice day!
Reply all
Reply to author
Forward
0 new messages