File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed
Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -38,18 +38,13 @@ internals.options = Validate.object().keys({
3838} ) ;
3939
4040
41- exports . inject = function ( dispatchFunc , options ) {
41+ exports . inject = async function ( dispatchFunc , options ) { // eslint-disable-line require-await
4242
4343 options = ( typeof options === 'string' ? { url : options } : options ) ;
4444
45- if ( options . validate !== false ) { // Defaults to true
46- try {
47- Hoek . assert ( typeof dispatchFunc === 'function' , 'Invalid dispatch function' ) ;
48- Validate . assert ( options , internals . options ) ;
49- }
50- catch ( err ) {
51- return Promise . reject ( err ) ;
52- }
45+ if ( options ?. validate !== false ) { // Defaults to true
46+ Hoek . assert ( typeof dispatchFunc === 'function' , 'Invalid or missing dispatch function' ) ;
47+ Validate . assert ( options ?? null , internals . options , 'Invalid options:' ) ;
5348 }
5449
5550 return new Promise ( ( resolve ) => {
Original file line number Diff line number Diff line change @@ -794,12 +794,15 @@ describe('_read()', () => {
794794
795795 it ( 'errors for invalid input options' , async ( ) => {
796796
797- await expect ( Shot . inject ( { } , { } ) ) . to . reject ( 'Invalid dispatch function' ) ;
797+ await expect ( Shot . inject ( ) ) . to . reject ( 'Invalid or missing dispatch function' ) ;
798+ await expect ( Shot . inject ( { } , { } ) ) . to . reject ( 'Invalid or missing dispatch function' ) ;
799+ await expect ( Shot . inject ( Hoek . ignore ) ) . to . reject ( / ^ I n v a l i d o p t i o n s : / ) ;
800+ await expect ( Shot . inject ( Hoek . ignore , true ) ) . to . reject ( / ^ I n v a l i d o p t i o n s : / ) ;
798801 } ) ;
799802
800803 it ( 'errors for missing url' , async ( ) => {
801804
802- const err = await expect ( Shot . inject ( ( req , res ) => { } , { } ) ) . to . reject ( ) ;
805+ const err = await expect ( Shot . inject ( ( req , res ) => { } , { } ) ) . to . reject ( / ^ I n v a l i d o p t i o n s : / ) ;
803806 expect ( err . isJoi ) . to . be . true ( ) ;
804807 } ) ;
805808
You can’t perform that action at this time.
0 commit comments