Skip to content

Commit 07c403d

Browse files
Julien HellerNoNameProvided
Julien Heller
authored andcommitted
test: add minimal test for async service initialization
1 parent 30f9e48 commit 07c403d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/decorators/Service.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,35 @@ describe('Service Decorator', function () {
172172
});
173173

174174
expect(Container.get(TestService)).toBe('TEST_STRING');
175+
176+
it('should support services with asynchronous initialization', async function () {
177+
@Service({ asyncInitialization: true })
178+
class Engine {
179+
ignition: string = 'off';
180+
initialized: Promise<any>;
181+
182+
constructor() {
183+
this.initialized = this.initialize();
184+
}
185+
186+
protected initialize() {
187+
return new Promise(resolve => {
188+
setTimeout(() => {
189+
this.ignition = 'running';
190+
resolve();
191+
}, 300);
192+
});
193+
}
194+
}
195+
196+
@Service()
197+
class Car {
198+
constructor(public engine: Engine) {}
199+
}
200+
201+
const car = await Container.getAsync<Car>(Car);
202+
203+
expect(car.engine.ignition).toEqual('running');
204+
});
175205
});
176206
});

0 commit comments

Comments
 (0)