Hi I am building an app using AngularJS and I am stuck at unit test section. I know how to write unit testing for controllers and all but I don't know how to do it for routeProvider. I am using Jasmine for writing unit test.
My route provider will look like 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 I write unit test for this routeProvider using Jasmine?
Keep it simple
Yes you can, is the quick answer and below is a little piece of code that can be used and extended to test that routes take you to the places you'd expect.