GregL
GregL

Reputation: 77

How to unit test a route in Hottowel Angular template?

I am trying to do a unit test on my admin route in the new hot-towel angular template. I am using jasmine & phantomjs with Resharper in visual studio 2013.

I'm sure that I am doing something wrong as I am new to angular testing. The $state is always empty or null. Is there something I need to do with $state after I inject it to have a valid state?

Here is the error I get.

       Expected null to equal '/admin'.
Error: Expected null to equal '/admin'.at stack (  jasmine.js: line 1442)

Admin Route Spec:

///<reference path="~\app\components\angular\angular.js" />
///<reference path="~\app\components\angular\angular-route.js" />
///<reference path="~\app\components\angular\angular-ui-router.js" />
///<reference path="~\app\components\angular\angular-mocks.js" />
///<reference path="~\app\components\jasmine\jasmine.js"/>
///<reference path="~\app\blocks\router\router-helper.provider.js"/>
///<reference path="~\app\blocks\router\router.module.js"/>
///<reference path="~\app\blocks\logger\logger.js"/>
///<reference path="~\app\blocks\logger\logger.module.js"/>
///<reference path="~\app\admin\admin.module.js"/>
///<reference path="~\app\admin\admin.controller.js"/>
describe('Admin Routes', function () {
 beforeEach(module('ui.router'));
 beforeEach(module('blocks.router'));
 beforeEach(module('blocks.logger'));
 beforeEach(module('app.admin'));

 var $rootScope, $state, $injector,
         adminView = 'app/admin/admin.html',state = 'admin';

 beforeEach(function () {
    inject(function(_$rootScope_, _$state_ , _$injector_, $templateCache) {
        $rootScope = _$rootScope_;
        $injector = _$injector_;
        $state = _$state_;

        $templateCache.put(adminView, '');
      });
    });

it('should map state admin to url /admin ', function() {          
   expect($state.href(state, {})).toEqual('/admin');     
});


});

Upvotes: 0

Views: 409

Answers (1)

jrweb247
jrweb247

Reputation: 95

dont' forget to include :

///<reference path="~\app\admin\admin.route.js"/>

Upvotes: 0

Related Questions