Skip to content

Instantly share code, notes, and snippets.

@cpoDesign
Created July 17, 2014 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpoDesign/87a7e83dc4527ccfb56d to your computer and use it in GitHub Desktop.
Save cpoDesign/87a7e83dc4527ccfb56d to your computer and use it in GitHub Desktop.
AngularJS - Unit testing routing
'use strict';
var app = angular.module('app', [ 'ngRoute']);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '/templates/Admin.html',
controller: 'HomeCtr'
})
.when('/news',{
templateUrl: '/templates/News.html',
controller: 'NewsCtr'
})
.otherwise({ redirectTo: '/' });
});
/// <reference path="../Scripts/jasmine.js" />
/// <reference path="../Scripts/angular.js" />
/// <reference path="../Scripts/angular-route.min.js" />
/// <reference path="../Scripts/angular-route.js" />
/// <reference path="../Scripts/angular-mocks.js" />
/// <reference path="../js/app.js" />
'use strict';
describe('Angular routing', function () {
beforeEach(module('app'));
it('home', inject(function ($route) {
expect($route.routes['/'].controller).toBe('HomeCtr');
expect($route.routes['/'].templateUrl).toBe('/templates/Admin.html');
}));
it('news', inject(function ($route) {
expect($route.routes['/news'].controller).toBe('NewsCtr');
expect($route.routes['/news'].templateUrl).toBe('/templates/News.html');
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment