Skip to content

Instantly share code, notes, and snippets.

@cyclopslabs
Created December 23, 2014 17:42
Show Gist options
  • Save cyclopslabs/2143bbabf06d12a637a3 to your computer and use it in GitHub Desktop.
Save cyclopslabs/2143bbabf06d12a637a3 to your computer and use it in GitHub Desktop.
Jasmine testing an Angular module
(function(){
/**
* @ngdoc overview
* @name core
*
* @description
* ## Module core
* Module to handle core components of the app.
* These items are not optional
*
* @requires ui.router
* @requires ngRoute
*
* @requires core.cache
* @requires core.filters
*
* @requires ui.modal
* @requires angular-loading-bar
* @requires angular-toaster
*
*/
angular.module('core', [
/*
* Angular Modules
*/
'ui.router',
'ngRoute',
/*
* App Core Modules
*/
'core.filters',
'core.cache',
/*
* 3rd party
*/
'ui.modal',
'angular-loading-bar',
'angular-toaster'
]);
})();
(function() {
'use strict';
/*
* This essentially tests that the module and it's dependencies have loaded properly.
*/
describe('core: Modules', function() {
describe("core Module:", function() {
var module;
beforeEach(function() {
module = angular.module("core");
});
it("should be registered", function() {
expect(module).not.toEqual(null);
});
describe("Dependencies:", function() {
var deps;
var hasModule = function(m) {
return deps.indexOf(m) >= 0;
};
beforeEach(function() {
deps = module.value('core').requires;
});
//Angular Modules
it("should have ui.router as a dependency", function() {
expect(hasModule('ui.router')).toEqual(true);
});
it("should have ngRoute as a dependency", function() {
expect(hasModule('ngRoute')).toEqual(true);
});
// App Core
it("should have core.filters as a dependency", function() {
expect(hasModule('core.filters')).toEqual(true);
});
it("should have core.cache as a dependency", function() {
expect(hasModule('core.cache')).toEqual(true);
});
//3rd Party Modules
it("should have ui.modal as a dependency", function() {
expect(hasModule('ui.modal')).toEqual(true);
});
it("should have angular-loading-bar as a dependency", function() {
expect(hasModule('angular-loading-bar')).toEqual(true);
});
it("should have angular-toaster as a dependency", function() {
expect(hasModule('angular-toaster')).toEqual(true);
});
});
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment