diff --git a/lib/core_dom/directive_injector.dart b/lib/core_dom/directive_injector.dart index 2c0f70329..65bbe53b6 100644 --- a/lib/core_dom/directive_injector.dart +++ b/lib/core_dom/directive_injector.dart @@ -254,7 +254,7 @@ class DirectiveInjector implements DirectiveBinder { case VISIBILITY_LOCAL: return 0; case VISIBILITY_DIRECT_CHILD: return 1; case VISIBILITY_CHILDREN: return _MAX_TREE_DEPTH; - default: throw null; + default: throw 'Invalid visibility "$visType"'; } } @@ -314,7 +314,7 @@ class DirectiveInjector implements DirectiveBinder { case DESTINATION_LIGHT_DOM_KEY_ID: return _destLightDom; case SOURCE_LIGHT_DOM_KEY_ID: return _sourceLightDom; case VIEW_KEY_ID: return _view; - default: new NoProviderError(_KEYS[keyId]); + default: throw new NoProviderError(_KEYS[keyId]); } } diff --git a/test/core_dom/directive_injector_spec.dart b/test/core_dom/directive_injector_spec.dart index f227765a2..9aad7b6ce 100644 --- a/test/core_dom/directive_injector_spec.dart +++ b/test/core_dom/directive_injector_spec.dart @@ -165,6 +165,30 @@ void main() { message: 'Cannot resolve a circular dependency! ' '(resolving _TypeC0 -> _TypeC1 -> _TypeC2 -> _TypeC1)'); }); + + it('should throw on invalid visibility', () { + var childInjector = + new DirectiveInjector(injector, appInjector, null, null, null, null, null); + + var key = new Key(_InvalidVisibility); + key.uid = -KEEP_ME_LAST; + + expect(() => childInjector.getByKey(key)) + .toThrowWith(message: 'Invalid visibility "-$KEEP_ME_LAST"'); + }); + + it('should throw on invalid id', () { + var childInjector = + new DirectiveInjector(injector, appInjector, null, null, null, null, null); + + var key = new Key(_InvalidId); + key.uid = KEEP_ME_LAST; + + expect(() =>childInjector.getByKey(key)) + .toThrowWith(message: 'No provider found for $KEEP_ME_LAST! ' + '(resolving _InvalidId -> $KEEP_ME_LAST)'); + }); + }); describe('Visibility', () { @@ -224,3 +248,6 @@ class _TypeA{ final _Type9 type9; _TypeA(this.type9); } class _TypeC0 {final _TypeC1 t; _TypeC0(this.t);} class _TypeC1 {final _TypeC2 t; _TypeC1(this.t);} class _TypeC2 {final _TypeC1 t; _TypeC2(this.t);} + +class _InvalidVisibility {} +class _InvalidId {}