fix(di): improve error messages for invalid bindings
Fixes #1515 Closes #1573
This commit is contained in:
parent
c0f3778dda
commit
ee1b574baf
|
@ -163,7 +163,7 @@ export class InvalidBindingError extends Error {
|
|||
message:string;
|
||||
constructor(binding) {
|
||||
super();
|
||||
this.message = `Invalid binding ${binding}`;
|
||||
this.message = `Invalid binding - only instances of Binding and Type are allowed, got: ${binding}`;
|
||||
}
|
||||
|
||||
toString():string {
|
||||
|
|
|
@ -379,7 +379,7 @@ function _resolveBindings(bindings:List): List {
|
|||
} else if (unresolved instanceof List) {
|
||||
resolved = _resolveBindings(unresolved);
|
||||
} else if (unresolved instanceof BindingBuilder) {
|
||||
throw new InvalidBindingError(unresolved.token);
|
||||
throw new InvalidBindingError('BindingBuilder with ' + unresolved.token + ' token');
|
||||
} else {
|
||||
throw new InvalidBindingError(unresolved);
|
||||
}
|
||||
|
|
|
@ -205,8 +205,11 @@ export function main() {
|
|||
});
|
||||
|
||||
it('should throw when given invalid bindings', function () {
|
||||
expect(() => Injector.resolveAndCreate(["blah"])).toThrowError('Invalid binding blah');
|
||||
expect(() => Injector.resolveAndCreate([bind("blah")])).toThrowError('Invalid binding blah');
|
||||
expect(() => Injector.resolveAndCreate(["blah"]))
|
||||
.toThrowError('Invalid binding - only instances of Binding and Type are allowed, got: blah');
|
||||
expect(() => Injector.resolveAndCreate([bind("blah")]))
|
||||
.toThrowError('Invalid binding - only instances of Binding and Type are allowed, ' +
|
||||
'got: BindingBuilder with blah token');
|
||||
});
|
||||
|
||||
it('should provide itself', function () {
|
||||
|
|
Loading…
Reference in New Issue