test(di): Add a test for sync binding + resolved async dependency

This commit is contained in:
Victor Berchet 2015-03-25 22:19:03 +01:00
parent 18ff2be9bb
commit 3ec837bfdb
1 changed files with 14 additions and 1 deletions

View File

@ -144,7 +144,7 @@ export function main() {
.toThrowError('Cannot instantiate UserList synchronously. It is provided as a promise!');
});
it('should throw when instantiating a sync binding with an dependency', function () {
it('should throw when instantiating a sync binding with an async dependency', function () {
var injector = new Injector([
bind(UserList).toAsyncFactory(fetchUsers),
UserController
@ -154,6 +154,19 @@ export function main() {
.toThrowError('Cannot instantiate UserList synchronously. It is provided as a promise! (UserController -> UserList)');
});
it('should not throw when instantiating a sync binding with a resolved async dependency',
inject([AsyncTestCompleter], (async) => {
var injector = new Injector([
bind(UserList).toAsyncFactory(fetchUsers),
UserController
]);
injector.asyncGet(UserList).then(() => {
expect(() => { injector.get(UserController); }).not.toThrow();
async.done();
});
}));
it('should resolve synchronously when an async dependency requested as a promise', function () {
var injector = new Injector([
bind(UserList).toAsyncFactory(fetchUsers),