feat($compile): throw error when directive name or factory fn is invalid

Closes: #15056
PR (#15057)
This commit is contained in:
Martin Staffa
2016-08-28 16:53:08 +02:00
committed by GitHub
parent e3a378e7a3
commit 53a3bf6634
2 changed files with 20 additions and 0 deletions
+1
View File
@@ -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);
+19
View File
@@ -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) {