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

fix(DirectiveInjector): fix exceptions #1484

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/core_dom/directive_injector.dart
Expand Up @@ -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"';
}
}

Expand Down Expand Up @@ -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]);
}
}

Expand Down
27 changes: 27 additions & 0 deletions test/core_dom/directive_injector_spec.dart
Expand Up @@ -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', () {
Expand Down Expand Up @@ -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 {}