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

Commit 87fcd1e

Browse files
vicbvsavkin
authored andcommitted
fix(DirectiveInjector): fix exceptions
Closes #1484
1 parent fd54c30 commit 87fcd1e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/core_dom/directive_injector.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class DirectiveInjector implements DirectiveBinder {
254254
case VISIBILITY_LOCAL: return 0;
255255
case VISIBILITY_DIRECT_CHILD: return 1;
256256
case VISIBILITY_CHILDREN: return _MAX_TREE_DEPTH;
257-
default: throw null;
257+
default: throw 'Invalid visibility "$visType"';
258258
}
259259
}
260260

@@ -314,7 +314,7 @@ class DirectiveInjector implements DirectiveBinder {
314314
case DESTINATION_LIGHT_DOM_KEY_ID: return _destLightDom;
315315
case SOURCE_LIGHT_DOM_KEY_ID: return _sourceLightDom;
316316
case VIEW_KEY_ID: return _view;
317-
default: new NoProviderError(_KEYS[keyId]);
317+
default: throw new NoProviderError(_KEYS[keyId]);
318318
}
319319
}
320320

test/core_dom/directive_injector_spec.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ void main() {
165165
message: 'Cannot resolve a circular dependency! '
166166
'(resolving _TypeC0 -> _TypeC1 -> _TypeC2 -> _TypeC1)');
167167
});
168+
169+
it('should throw on invalid visibility', () {
170+
var childInjector =
171+
new DirectiveInjector(injector, appInjector, null, null, null, null, null);
172+
173+
var key = new Key(_InvalidVisibility);
174+
key.uid = -KEEP_ME_LAST;
175+
176+
expect(() => childInjector.getByKey(key))
177+
.toThrowWith(message: 'Invalid visibility "-$KEEP_ME_LAST"');
178+
});
179+
180+
it('should throw on invalid id', () {
181+
var childInjector =
182+
new DirectiveInjector(injector, appInjector, null, null, null, null, null);
183+
184+
var key = new Key(_InvalidId);
185+
key.uid = KEEP_ME_LAST;
186+
187+
expect(() =>childInjector.getByKey(key))
188+
.toThrowWith(message: 'No provider found for $KEEP_ME_LAST! '
189+
'(resolving _InvalidId -> $KEEP_ME_LAST)');
190+
});
191+
168192
});
169193

170194
describe('Visibility', () {
@@ -224,3 +248,6 @@ class _TypeA{ final _Type9 type9; _TypeA(this.type9); }
224248
class _TypeC0 {final _TypeC1 t; _TypeC0(this.t);}
225249
class _TypeC1 {final _TypeC2 t; _TypeC1(this.t);}
226250
class _TypeC2 {final _TypeC1 t; _TypeC2(this.t);}
251+
252+
class _InvalidVisibility {}
253+
class _InvalidId {}

0 commit comments

Comments
 (0)