File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -681,8 +681,12 @@ function fastify (options) {
681
681
this [ kHooks ] . add ( name , fn )
682
682
} else {
683
683
this . after ( ( err , done ) => {
684
- _addHook . call ( this , name , fn )
685
- done ( err )
684
+ try {
685
+ _addHook . call ( this , name , fn )
686
+ done ( err )
687
+ } catch ( err ) {
688
+ done ( err )
689
+ }
686
690
} )
687
691
}
688
692
return this
Original file line number Diff line number Diff line change 2
2
3
3
const { test } = require ( 'node:test' )
4
4
const { Hooks } = require ( '../../lib/hooks' )
5
+ const { default : fastify } = require ( '../../fastify' )
5
6
const noop = ( ) => { }
6
7
7
8
test ( 'hooks should have 4 array with the registered hooks' , t => {
@@ -77,3 +78,19 @@ test('should throw on wrong parameters', t => {
77
78
t . assert . strictEqual ( e . message , 'onSend hook should be a function, instead got [object Null]' )
78
79
}
79
80
} )
81
+
82
+ test ( 'Integration test: internal function _addHook should be turned into app.ready() rejection' , async ( t ) => {
83
+ const app = fastify ( )
84
+
85
+ app . register ( async function ( ) {
86
+ app . addHook ( 'notRealHook' , async ( ) => { } )
87
+ } )
88
+
89
+ try {
90
+ await app . ready ( )
91
+ t . assert . fail ( 'Expected ready() to throw' )
92
+ } catch ( err ) {
93
+ t . assert . strictEqual ( err . code , 'FST_ERR_HOOK_NOT_SUPPORTED' )
94
+ t . assert . match ( err . message , / h o o k n o t s u p p o r t e d / i)
95
+ }
96
+ } )
You can’t perform that action at this time.
0 commit comments