Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat(compiler): Throw a useful error message on a missing NgComponene…
Browse files Browse the repository at this point in the history
…t selector
  • Loading branch information
jbdeboer committed Jan 8, 2014
1 parent e13d5b5 commit 42692a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/core_dom/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ DirectiveSelector directiveSelectorFactory(DirectiveMap directives) {
_ElementSelector elementSelector = new _ElementSelector('');
List<_ContainsSelector> attrSelector = [];
List<_ContainsSelector> textSelector = [];

directives.forEach((NgAnnotation annotation, Type type) {
var match;
var selector = annotation.selector;
List<_SelectorPart> selectorParts;
if (selector == null) {
throw new ArgumentError('Missing selector annotation for $type');
}

if ((match = _CONTAINS_REGEXP.firstMatch(selector)) != null) {
textSelector.add(new _ContainsSelector(annotation, match.group(1)));
Expand Down
25 changes: 25 additions & 0 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,24 @@ main() => describe('dte.compiler', () {
expect(element.textWithShadow()).toEqual('WORKED');
})));
});

describe('invalid components', () {
beforeEach(module((Module module) {
module
..type(MissingSelector);
return (Injector _injector) {
injector = _injector;
$compile = injector.get(Compiler);
$rootScope = injector.get(Scope);
};
}));

it('should throw a useful error message', () {
expect(() {
inject((Compiler c) { });
}).toThrow('Missing selector annotation for MissingSelector');
});
});
});


Expand Down Expand Up @@ -720,3 +738,10 @@ class MyController {
}
}

@NgComponent(
template: 'boo'
)
class MissingSelector {

}

0 comments on commit 42692a1

Please sign in to comment.