Last active
August 29, 2015 14:25
-
-
Save alexilyaev/b0eb3748ed8dd6753d41 to your computer and use it in GitHub Desktop.
Simple Angular Directive spec boilerplate
This file contains 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
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