@@ -56,7 +56,7 @@ describe('MiddlewareModule', () => {
5656 } ;
5757
5858 await middlewareModule . loadConfiguration (
59- new MiddlewareContainer ( ) ,
59+ new MiddlewareContainer ( new NestContainer ( ) ) ,
6060 mockModule as any ,
6161 'Test' as any ,
6262 ) ;
@@ -71,27 +71,35 @@ describe('MiddlewareModule', () => {
7171 } ) ;
7272
7373 describe ( 'registerRouteMiddleware' , ( ) => {
74+ class TestModule { }
75+
76+ let nestContainer : NestContainer ;
77+
78+ beforeEach ( ( ) => {
79+ nestContainer = new NestContainer ( ) ;
80+ nestContainer
81+ . getModules ( )
82+ . set ( 'Test' , new Module ( TestModule , [ ] , nestContainer ) ) ;
83+ } ) ;
7484 it ( 'should throw "RuntimeException" exception when middleware is not stored in container' , ( ) => {
7585 const route = { path : 'Test' } ;
7686 const configuration = {
7787 middleware : [ TestMiddleware ] ,
7888 forRoutes : [ BaseController ] ,
7989 } ;
80-
8190 const useSpy = sinon . spy ( ) ;
8291 const app = { use : useSpy } ;
8392
84- const nestContainer = new NestContainer ( ) ;
8593 // tslint:disable-next-line:no-string-literal
8694 middlewareModule [ 'container' ] = nestContainer ;
8795
8896 expect (
8997 middlewareModule . registerRouteMiddleware (
90- new MiddlewareContainer ( ) ,
98+ new MiddlewareContainer ( nestContainer ) ,
9199 route as any ,
92100 configuration ,
93- 'Test' as any ,
94- app as any ,
101+ 'Test' ,
102+ app ,
95103 ) ,
96104 ) . to . eventually . be . rejectedWith ( RuntimeException ) ;
97105 } ) ;
@@ -109,8 +117,8 @@ describe('MiddlewareModule', () => {
109117 const useSpy = sinon . spy ( ) ;
110118 const app = { use : useSpy } ;
111119
112- const container = new MiddlewareContainer ( ) ;
113- const moduleKey = 'Test' as any ;
120+ const container = new MiddlewareContainer ( nestContainer ) ;
121+ const moduleKey = 'Test' ;
114122 container . insertConfig ( [ configuration ] , moduleKey ) ;
115123
116124 const instance = new InvalidMiddleware ( ) ;
@@ -125,7 +133,7 @@ describe('MiddlewareModule', () => {
125133 route as any ,
126134 configuration ,
127135 moduleKey ,
128- app as any ,
136+ app ,
129137 ) ,
130138 ) . to . be . rejectedWith ( InvalidMiddlewareException ) ;
131139 } ) ;
@@ -143,7 +151,7 @@ describe('MiddlewareModule', () => {
143151 const app = {
144152 createMiddlewareFactory : createMiddlewareFactoryStub ,
145153 } ;
146- const container = new MiddlewareContainer ( ) ;
154+ const container = new MiddlewareContainer ( new NestContainer ( ) ) ;
147155 const moduleKey = 'Test' ;
148156 container . insertConfig ( [ configuration ] , moduleKey ) ;
149157
@@ -155,7 +163,6 @@ describe('MiddlewareModule', () => {
155163 instance,
156164 } ) ,
157165 ) ;
158- const nestContainer = new NestContainer ( ) ;
159166 sinon
160167 . stub ( nestContainer , 'getModuleByKey' )
161168 . callsFake ( ( ) => new Module ( class { } , [ ] , nestContainer ) ) ;
0 commit comments