Skip to content

Commit e7cbb28

Browse files
author
Julien Heller
committed
Add test
1 parent 4e0b14a commit e7cbb28

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

test/decorators/Service.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "reflect-metadata";
22
import {Container} from "../../src/Container";
33
import {Service} from "../../src/decorators/Service";
4+
import {AsyncInitializedService} from "../../src/types/AsyncInitializedService";
45

56
describe("Service Decorator", function() {
67

@@ -99,7 +100,7 @@ describe("Service Decorator", function() {
99100

100101
});
101102

102-
it("should support factory function with arguments", function() {
103+
it("should support factory class with arguments on create method", function() {
103104

104105
@Service()
105106
class Engine {
@@ -183,4 +184,28 @@ describe("Service Decorator", function() {
183184
scopedContainer.get(Engine).name.should.be.equal("sporty");
184185
});
185186

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+
});
186211
});

0 commit comments

Comments
 (0)