From ee1b574baf38e833de08a91c5521791d52e3d47c Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Tue, 28 Apr 2015 14:24:20 +0200 Subject: [PATCH] fix(di): improve error messages for invalid bindings Fixes #1515 Closes #1573 --- modules/angular2/src/di/exceptions.js | 2 +- modules/angular2/src/di/injector.js | 2 +- modules/angular2/test/di/injector_spec.js | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/angular2/src/di/exceptions.js b/modules/angular2/src/di/exceptions.js index 3d99ea2e89..c0aea9a062 100644 --- a/modules/angular2/src/di/exceptions.js +++ b/modules/angular2/src/di/exceptions.js @@ -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 { diff --git a/modules/angular2/src/di/injector.js b/modules/angular2/src/di/injector.js index 3dc128eebf..127e2e8bd3 100644 --- a/modules/angular2/src/di/injector.js +++ b/modules/angular2/src/di/injector.js @@ -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); } diff --git a/modules/angular2/test/di/injector_spec.js b/modules/angular2/test/di/injector_spec.js index 8bd11f2a1e..cb2aa85375 100644 --- a/modules/angular2/test/di/injector_spec.js +++ b/modules/angular2/test/di/injector_spec.js @@ -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 () {