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

Commit 53a3bf6

Browse files
authored
feat($compile): throw error when directive name or factory fn is invalid
Closes: #15056 PR (#15057)
1 parent e3a378e commit 53a3bf6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/ng/compile.js

+1
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10871087
* @returns {ng.$compileProvider} Self for chaining.
10881088
*/
10891089
this.directive = function registerDirective(name, directiveFactory) {
1090+
assertArg(name, 'name');
10901091
assertNotHasOwnProperty(name, 'directive');
10911092
if (isString(name)) {
10921093
assertValidDirectiveName(name);

test/ng/compileSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ describe('$compile', function() {
214214
});
215215
inject(function($compile) {});
216216
});
217+
217218
it('should throw an exception if a directive name has leading or trailing whitespace', function() {
218219
module(function() {
219220
function assertLeadingOrTrailingWhitespaceInDirectiveName(name) {
@@ -230,6 +231,24 @@ describe('$compile', function() {
230231
inject(function($compile) {});
231232
});
232233

234+
it('should throw an exception if the directive name is not defined', function() {
235+
module(function() {
236+
expect(function() {
237+
directive();
238+
}).toThrowMinErr('ng','areq');
239+
});
240+
inject(function($compile) {});
241+
});
242+
243+
it('should throw an exception if the directive factory is not defined', function() {
244+
module(function() {
245+
expect(function() {
246+
directive('myDir');
247+
}).toThrowMinErr('ng','areq');
248+
});
249+
inject(function($compile) {});
250+
});
251+
233252
it('should preserve context within declaration', function() {
234253
module(function() {
235254
directive('ff', function(log) {

0 commit comments

Comments
 (0)