@@ -41,6 +41,7 @@ describe('RouterExecutionContext', () => {
4141 describe ( 'create' , ( ) => {
4242 describe ( 'when callback metadata is not undefined' , ( ) => {
4343 let metadata : RouteParamsMetadata ;
44+ let exchangeKeysForValuesSpy : sinon . SinonSpy ;
4445 beforeEach ( ( ) => {
4546 metadata = {
4647 [ RouteParamtypes . NEXT ] : { index : 0 } ,
@@ -51,6 +52,17 @@ describe('RouterExecutionContext', () => {
5152 } ;
5253 sinon . stub ( contextCreator , 'reflectCallbackMetadata' ) . returns ( metadata ) ;
5354 sinon . stub ( contextCreator , 'reflectCallbackParamtypes' ) . returns ( [ ] ) ;
55+ exchangeKeysForValuesSpy = sinon . spy ( contextCreator , 'exchangeKeysForValues' ) ;
56+ } ) ;
57+ it ( 'should call "exchangeKeysForValues" with expected arguments' , ( done ) => {
58+ const keys = Object . keys ( metadata ) ;
59+
60+ contextCreator . create ( { foo : 'bar' } , callback as any , '' , 0 ) ;
61+ expect ( exchangeKeysForValuesSpy . called ) . to . be . true ;
62+ expect (
63+ exchangeKeysForValuesSpy . calledWith ( keys , metadata ) ,
64+ ) . to . be . true ;
65+ done ( ) ;
5466 } ) ;
5567 describe ( 'returns proxy function' , ( ) => {
5668 let proxyContext ;
@@ -64,7 +76,6 @@ describe('RouterExecutionContext', () => {
6476 expect ( proxyContext ) . to . be . a ( 'function' ) ;
6577 } ) ;
6678 describe ( 'when proxy function called' , ( ) => {
67- let exchangeKeysForValuesSpy : sinon . SinonSpy ;
6879 let request ;
6980 const response = {
7081 status : ( ) => response ,
@@ -79,18 +90,6 @@ describe('RouterExecutionContext', () => {
7990 test : 3 ,
8091 } ,
8192 } ;
82- exchangeKeysForValuesSpy = sinon . spy ( contextCreator , 'exchangeKeysForValues' ) ;
83- } ) ;
84- it ( 'should call "exchangeKeysForValues" with expected arguments' , ( done ) => {
85- proxyContext ( request , response , next ) . then ( ( ) => {
86- const keys = Object . keys ( metadata ) ;
87-
88- expect ( exchangeKeysForValuesSpy . called ) . to . be . true ;
89- expect (
90- exchangeKeysForValuesSpy . calledWith ( keys , metadata , { req : request , res : response , next } ) ,
91- ) . to . be . true ;
92- done ( ) ;
93- } ) ;
9493 } ) ;
9594 it ( 'should apply expected context and arguments to callback' , ( done ) => {
9695 proxyContext ( request , response , next ) . then ( ( ) => {
@@ -161,12 +160,13 @@ describe('RouterExecutionContext', () => {
161160 } ,
162161 } ;
163162 const keys = Object . keys ( metadata ) ;
164- const values = contextCreator . exchangeKeysForValues ( keys , metadata , { res , req , next } ) ;
163+ const values = contextCreator . exchangeKeysForValues ( keys , metadata ) ;
165164 const expectedValues = [
166- { index : 0 , value : req , type : RouteParamtypes . REQUEST , data : 'test' , pipes : [ ] } ,
167- { index : 2 , value : req . body . test , type : RouteParamtypes . BODY , data : 'test' , pipes : [ ] } ,
165+ { index : 0 , type : RouteParamtypes . REQUEST , data : 'test' } ,
166+ { index : 2 , type : RouteParamtypes . BODY , data : 'test' } ,
168167 ] ;
169- expect ( values ) . to . deep . equal ( expectedValues ) ;
168+ expect ( values [ 0 ] ) . to . deep . include ( expectedValues [ 0 ] ) ;
169+ expect ( values [ 1 ] ) . to . deep . include ( expectedValues [ 1 ] ) ;
170170 } ) ;
171171 } ) ;
172172 describe ( 'getParamValue' , ( ) => {
0 commit comments