Created
August 6, 2014 18:26
-
-
Save cybersamx/9b1994fe7eee4b969ac4 to your computer and use it in GitHub Desktop.
Inject a custom AngularJS directive object to a (Jasmine) unit test spec.
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
// Simple AngularJS directive | |
var directives = angular.module('myNameSpace.directives', []); | |
directives.directive('directive', function() { | |
var directive = {}; | |
directive.restrict = 'E'; // Indicates an element directive. | |
directive.template = 'Hello World'; | |
return directive; | |
}); | |
// Test | |
describe('myNameSpace.directives', function() { | |
var element, scope; | |
beforeEach(module('myNameSpace.directives')); | |
beforeEach(inject(function($rootScope, $compile) { | |
element = angular.element( | |
'<directive>Old text</directive>' | |
); | |
scope = $rootScope.$new(); | |
$compile(element)(scope); | |
scope.$digest(); | |
})); | |
it('should display the text properly', function() { | |
expect(element.html()).toBe('Hello World'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment