@@ -212,7 +212,7 @@ describe('handler', function() {
212212 } ) ;
213213 } ) ;
214214
215- it ( 'middleware can override result after next()' , function ( ) {
215+ it ( 'middleware can override result after await next()' , function ( ) {
216216 const stub = sinon . stub ( ) . returns ( 'foo' ) ;
217217 const fixture = lambdaHandler ( )
218218 . use ( async ( event , context , next ) => {
@@ -228,6 +228,24 @@ describe('handler', function() {
228228 } ) ;
229229 } ) ;
230230
231+ it ( 'middleware can override result after return next()' , function ( ) {
232+ const stub = sinon . stub ( ) . returns ( 'foo' ) ;
233+ const fixture = lambdaHandler ( )
234+ . use ( async ( event , context , next ) => {
235+ return next ( )
236+ . then ( ( ) => {
237+ return 'bar' ;
238+ } ) ;
239+ } )
240+ . use ( stub ) ;
241+
242+ return fixture ( testEvent , testContext )
243+ . then ( result => {
244+ expect ( result ) . to . equal ( 'bar' ) ;
245+ expect ( stub . calledOnce ) . to . be . true ;
246+ } ) ;
247+ } ) ;
248+
231249 it ( 'can do things around next() without affecting result' , function ( ) {
232250 const obj = { } ;
233251 let after = false ;
@@ -245,6 +263,20 @@ describe('handler', function() {
245263 } ) ;
246264 } ) ;
247265
266+ it ( 'can have middleware return next() without affecting result value' , function ( ) {
267+ const obj = { } ;
268+ const fixture = lambdaHandler ( )
269+ . use ( ( event , context , next ) => {
270+ return next ( ) ;
271+ } )
272+ . use ( ( ) => obj ) ;
273+
274+ return fixture ( testEvent , testContext )
275+ . then ( result => {
276+ expect ( result ) . to . equal ( obj ) ;
277+ } ) ;
278+ } ) ;
279+
248280 it ( 'has expected execution order' , function ( ) {
249281 const order = [ ] ;
250282 const fixture = lambdaHandler ( )
0 commit comments