Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

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

Merged
merged 1 commit into from
Aug 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down