Skip to content

Instantly share code, notes, and snippets.

@davisford
Created December 10, 2012 18:50
Show Gist options
  • Save davisford/4252485 to your computer and use it in GitHub Desktop.
Save davisford/4252485 to your computer and use it in GitHub Desktop.
mocha + testacular + angular
/*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;
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' : '';
};
}]);
/*global angular:false */
'use strict';
angular.module('app.filters', []).
.filter('interpolate', function (version) {
return function (text) {
return String(text).replace(/\%VERSION\%/mg, version);
};
});
'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