feat($compile): throw error when directive name or factory fn is invalid
Closes: #15056 PR (#15057)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user