Skip to content

Commit 89bdaa4

Browse files
committed
Failing test for #61
1 parent 61cda52 commit 89bdaa4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import "reflect-metadata";
2+
import {Container} from "../../../src/Container";
3+
import {Service} from "../../../src/decorators/Service";
4+
5+
describe("github issues > #61 Scoped container creates new instance of service every time", function() {
6+
7+
beforeEach(() => Container.reset());
8+
9+
it("should work properly", function() {
10+
11+
@Service()
12+
class Car {
13+
public serial = Math.random();
14+
}
15+
16+
const fooContainer = Container.of("foo");
17+
const barContainer = Container.of("bar");
18+
19+
const car1Serial = Container.get(Car).serial;
20+
const car2Serial = Container.get(Car).serial;
21+
22+
const fooCar1Serial = fooContainer.get(Car).serial;
23+
const fooCar2Serial = fooContainer.get(Car).serial;
24+
25+
const barCar1Serial = barContainer.get(Car).serial;
26+
const barCar2Serial = barContainer.get(Car).serial;
27+
28+
car1Serial.should.be.equal(car2Serial);
29+
fooCar1Serial.should.be.equal(fooCar2Serial);
30+
barCar1Serial.should.be.equal(barCar2Serial);
31+
32+
car1Serial.should.not.be.equal(fooCar1Serial);
33+
car1Serial.should.not.be.equal(barCar1Serial);
34+
fooCar1Serial.should.not.be.equal(barCar1Serial);
35+
});
36+
37+
});

0 commit comments

Comments
 (0)