File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -172,5 +172,35 @@ describe('Service Decorator', function () {
172
172
} ) ;
173
173
174
174
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
+ } ) ;
175
205
} ) ;
176
206
} ) ;
You can’t perform that action at this time.
0 commit comments