File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ module.exports = function(registry) {
197197 this . _runWhenAttachedToApp ( function ( app ) {
198198 var remotes = app . remotes ( ) ;
199199 remotes . before ( className + '.' + name , function ( ctx , next ) {
200- fn ( ctx , ctx . result , next ) ;
200+ return fn ( ctx , ctx . result , next ) ;
201201 } ) ;
202202 } ) ;
203203 } ;
@@ -208,7 +208,7 @@ module.exports = function(registry) {
208208 this . _runWhenAttachedToApp ( function ( app ) {
209209 var remotes = app . remotes ( ) ;
210210 remotes . after ( className + '.' + name , function ( ctx , next ) {
211- fn ( ctx , ctx . result , next ) ;
211+ return fn ( ctx , ctx . result , next ) ;
212212 } ) ;
213213 } ) ;
214214 } ;
Original file line number Diff line number Diff line change @@ -301,6 +301,32 @@ describe.onServer('Remote Methods', function() {
301301 done ( ) ;
302302 } ) ;
303303 } ) ;
304+
305+ it ( 'Does not stop the hook chain after returning a promise' , function ( done ) {
306+ var hooksCalled = [ ] ;
307+
308+ User . beforeRemote ( 'create' , function ( ) {
309+ hooksCalled . push ( 'first' ) ;
310+ return Promise . resolve ( ) ;
311+ } ) ;
312+
313+ User . beforeRemote ( 'create' , function ( ctx , user , next ) {
314+ hooksCalled . push ( 'second' ) ;
315+ next ( ) ;
316+ } ) ;
317+
318+ // invoke save
319+ request ( app )
320+ . post ( '/users' )
321+ . send ( { data : { first : 'foo' , last : 'bar' } } )
322+ . expect ( 'Content-Type' , / j s o n / )
323+ . expect ( 200 )
324+ . end ( function ( err , res ) {
325+ if ( err ) return done ( err ) ;
326+ expect ( hooksCalled ) . to . eql ( [ 'first' , 'second' ] ) ;
327+ done ( ) ;
328+ } ) ;
329+ } ) ;
304330 } ) ;
305331
306332 describe ( 'Model.afterRemote(name, fn)' , function ( ) {
You can’t perform that action at this time.
0 commit comments