Skip to content

Commit

Permalink
fix(coreDirectives): Added an Error Message for invalid selectors on …
Browse files Browse the repository at this point in the history
…component annotation

If the component selector is an empty string or not a string an error will be thrown.

Closes angular#3464
  • Loading branch information
Daniel Rasmuson committed Aug 26, 2015
1 parent 8ed22ce commit 0abae75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/angular2/src/core/metadata/directives.ts
@@ -1,4 +1,4 @@
import {CONST, CONST_EXPR} from 'angular2/src/core/facade/lang';
import {CONST, CONST_EXPR, isString, isBlank, makeTypeError} from 'angular2/src/core/facade/lang';
import {List} from 'angular2/src/core/facade/collection';
import {InjectableMetadata} from 'angular2/src/core/di/metadata';
import {DEFAULT} from 'angular2/change_detection';
Expand Down Expand Up @@ -859,6 +859,9 @@ export class ComponentMetadata extends DirectiveMetadata {
viewBindings?: List<any>,
changeDetection?: string,
} = {}) {
if (!isBlank(selector) && !(isString(selector) && selector.length > 0)) {
throw makeTypeError('The component annotation requires a string selector.');
}
super({
selector: selector,
properties: properties,
Expand Down
19 changes: 19 additions & 0 deletions modules/angular2/test/core/compiler/element_injector_spec.ts
Expand Up @@ -513,6 +513,25 @@ export function main() {
expect(pei.getBindingAtIndex(i).key.token).toBe(i);
}
});

it('should not error if selector is undefined', () => {
expect(function(){
new ComponentMetadata();
}).not.toThrow()
});

it('should throw an error if the selector is an empty string', () => {
expect(function(){
new ComponentMetadata({selector: ''});
}).toThrowError("The component annotation requires a string selector.")
});

it('should throw an error if selector is not a string', () => {
expect(function(){
new ComponentMetadata({selector: {x: 'selector'}});
}).toThrowError("The component annotation requires a string selector.")
});

});
});

Expand Down

0 comments on commit 0abae75

Please sign in to comment.