Skip to content

Instantly share code, notes, and snippets.

@alexilyaev
Last active August 29, 2015 14:25
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 alexilyaev/b0eb3748ed8dd6753d41 to your computer and use it in GitHub Desktop.
Save alexilyaev/b0eb3748ed8dd6753d41 to your computer and use it in GitHub Desktop.
Simple Angular Directive spec boilerplate
describe('test.directive', function () {
'use strict';
var $rootScope;
var $scope;
var $compile;
var preCompiledElement;
var element;
var controller;
/**
* Helper functions
*/
/**
* Renders a pre-compiled element and gets it's Controller
*/
function renderElement() {
element = $compile(preCompiledElement)($scope);
$scope.$digest();
controller = element.controller('test');
}
/**
* Execute `renderElement` in a function
* Used to test the render process throws appropriate errors
*/
function testRenderException() {
renderElement();
}
/**
* Setup
*/
beforeEach(function () {
// Load required Modules
});
beforeEach(inject(function ($injector, _$rootScope_, _$compile_) {
$rootScope = _$rootScope_;
$compile = _$compile_;
$scope = $rootScope.$new();
// Cache a precompiled element of the tested directive
preCompiledElement = angular.element('<test></test>');
// Reset previously set values
element = undefined;
controller = undefined;
}));
/**
* Test directive attributes
*/
describe('Arguments', function () {
// some code
});
/**
* Test Directive Controller
*/
describe('Controller', function () {
// some code
});
/**
* Test integration with surrounding logic
*/
describe('Integration', function () {
// some code
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment