diff --git a/src/ng/compile.js b/src/ng/compile.js index e61307f3760f..942eca582a26 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1087,6 +1087,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { * @returns {ng.$compileProvider} Self for chaining. */ this.directive = function registerDirective(name, directiveFactory) { + assertArg(name, 'name'); assertNotHasOwnProperty(name, 'directive'); if (isString(name)) { assertValidDirectiveName(name); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 800fb1be9d27..bc35c692c7a8 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -214,6 +214,7 @@ describe('$compile', function() { }); inject(function($compile) {}); }); + it('should throw an exception if a directive name has leading or trailing whitespace', function() { module(function() { function assertLeadingOrTrailingWhitespaceInDirectiveName(name) { @@ -230,6 +231,24 @@ describe('$compile', function() { inject(function($compile) {}); }); + it('should throw an exception if the directive name is not defined', function() { + module(function() { + expect(function() { + directive(); + }).toThrowMinErr('ng','areq'); + }); + inject(function($compile) {}); + }); + + it('should throw an exception if the directive factory is not defined', function() { + module(function() { + expect(function() { + directive('myDir'); + }).toThrowMinErr('ng','areq'); + }); + inject(function($compile) {}); + }); + it('should preserve context within declaration', function() { module(function() { directive('ff', function(log) {