File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments