File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
1
import "reflect-metadata" ;
2
2
import { Container } from "../../src/Container" ;
3
3
import { Service } from "../../src/decorators/Service" ;
4
+ import { AsyncInitializedService } from "../../src/types/AsyncInitializedService" ;
4
5
5
6
describe ( "Service Decorator" , function ( ) {
6
7
@@ -99,7 +100,7 @@ describe("Service Decorator", function() {
99
100
100
101
} ) ;
101
102
102
- it ( "should support factory function with arguments" , function ( ) {
103
+ it ( "should support factory class with arguments on create method " , function ( ) {
103
104
104
105
@Service ( )
105
106
class Engine {
@@ -183,4 +184,28 @@ describe("Service Decorator", function() {
183
184
scopedContainer . get ( Engine ) . name . should . be . equal ( "sporty" ) ;
184
185
} ) ;
185
186
187
+ it ( "should support services with asynchronous initialization" , async function ( ) {
188
+
189
+ @Service ( { asyncInitialization : true } )
190
+ class Engine extends AsyncInitializedService {
191
+ ignition : string = "off" ;
192
+
193
+ protected initialize ( ) {
194
+ return new Promise ( ( resolve ) => {
195
+ setTimeout ( ( ) => {
196
+ this . ignition = "running" ;
197
+ resolve ( ) ;
198
+ } , 0 ) ;
199
+ } ) ;
200
+ }
201
+ }
202
+
203
+ @Service ( )
204
+ class Car {
205
+ constructor ( public engine : Engine ) {
206
+ }
207
+ }
208
+
209
+ ( await Container . getAsync ( Car ) ) . engine . ignition . should . be . equal ( "running" ) ;
210
+ } ) ;
186
211
} ) ;
You can’t perform that action at this time.
0 commit comments