Can we write unit test for AngularJS routeProvider? -
hi building app using angularjs , stuck @ unit test section. know how write unit testing controllers , don't know how routeprovider. using jasmine writing unit test.
my route provider this;
var app = angular.module('myapp', ['ngresource']) app.config(function ($routeprovider) { $routeprovider .when('/', { templateurl: 'app/views/main.html', controller: 'mainctrl' }) .when('/home/:partyid', { templateurl: 'app/views/home.html', controller: 'homectrl' }) .when('/edit/:partyid', { templateurl: 'app/views/update_profile.html', controller: 'editctrl' }) .when('/route', { templateurl: 'app/views/route.html', controller: 'routectrl' }) .when('/signup', { templateurl: 'app/views/signup.html', controller: 'signupctrl' }) .when('/login', { templateurl: 'app/views/login.html', controller: 'loginctrl' }) .otherwise({ redirectto: '/' }); });
how can write unit test routeprovider using jasmine?
yes can, quick answer , below little piece of code can used , extended test routes take places you'd expect.
describe('testing routes', function() { beforeeach(module('windscreens')); var location, route, rootscope; beforeeach(inject( function( _$location_, _$route_, _$rootscope_ ) { location = _$location_; route = _$route_; rootscope = _$rootscope_; })); describe('login route', function() { beforeeach(inject( function($httpbackend) { $httpbackend.expectget('login') .respond(200); })); it('should load login page on successful load of /login', function() { location.path('/login'); rootscope.$digest(); expect(route.current.controller).tobe('loginctrl') }); }); });
Comments
Post a Comment