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

Commit

Permalink
fix(DirectiveInjector): fix exceptions
Browse files Browse the repository at this point in the history
Closes #1484
  • Loading branch information
vicb authored and vsavkin committed Sep 22, 2014
1 parent fd54c30 commit 87fcd1e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/core_dom/directive_injector.dart
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 {}

0 comments on commit 87fcd1e

Please sign in to comment.