Created
December 10, 2012 18:50
-
-
Save davisford/4252485 to your computer and use it in GitHub Desktop.
mocha + testacular + angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global angular:false */ | |
'use strict'; | |
// this is the main angular application modeule | |
var app = angular.module('app', ['app.filters', 'app.services', 'app.directives', 'ui']). | |
config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { | |
// setup routing | |
$routeProvider.when("/home", { | |
// represents a single home view | |
action: "foo" | |
}).otherwise({ | |
redirectTo: "/home" | |
}); | |
// use HTML5 mode for pushstate | |
$locationProvider.html5Mode(true); | |
}]); | |
module.exports = app; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('/app'); | |
app.controller('NavCtrl', ['$scope', '$location', function NavCtrl($scope, $location) { | |
// controls css class for nav menu items | |
$scope.navClass = function (page) { | |
// if host:port/foo is url and page === foo, then class="active" | |
var current = $location.path().substring(1); | |
return page === current ? 'active' : ''; | |
}; | |
}]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global angular:false */ | |
'use strict'; | |
angular.module('app.filters', []). | |
.filter('interpolate', function (version) { | |
return function (text) { | |
return String(text).replace(/\%VERSION\%/mg, version); | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var assert = chai.assert, | |
expect = chai.expect, | |
should = chai.should(), | |
$injector = angular.injector(['app', 'ng']), | |
$controller = $injector.get('$controller'), | |
$scope = $injector.get('$rootScope'); | |
describe('app controllers', function () { | |
describe('NavCtrl', function () { | |
it('should return the "active" class when selected', function () { | |
var scope = {}, | |
ctrl = $controller('NavCtrl'); | |
ctrl.navClass('devices').should.equal(''); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment