@@ -537,6 +537,44 @@ describe('inject()', () => {
537537 } ) ;
538538 expect ( res . payload . toString ( ) ) . to . equal ( body . toString ( ) ) ;
539539 } ) ;
540+
541+ it ( 'errors for invalid input options' , async ( ) => {
542+
543+ await expect ( Shot . inject ( ) ) . to . reject ( 'Invalid or missing dispatch function' ) ;
544+ await expect ( Shot . inject ( { } , { } ) ) . to . reject ( 'Invalid or missing dispatch function' ) ;
545+ await expect ( Shot . inject ( Hoek . ignore ) ) . to . reject ( / ^ I n v a l i d o p t i o n s : / ) ;
546+ await expect ( Shot . inject ( Hoek . ignore , true ) ) . to . reject ( / ^ I n v a l i d o p t i o n s : / ) ;
547+ } ) ;
548+
549+ it ( 'errors for missing url' , async ( ) => {
550+
551+ const err = await expect ( Shot . inject ( ( req , res ) => { } , { } ) ) . to . reject ( / ^ I n v a l i d o p t i o n s : / ) ;
552+ expect ( err . isJoi ) . to . be . true ( ) ;
553+ } ) ;
554+
555+ it ( 'errors for an incorrect simulation object' , async ( ) => {
556+
557+ const err = await expect ( Shot . inject ( ( req , res ) => { } , { url : '/' , simulate : 'sample string' } ) ) . to . reject ( ) ;
558+ expect ( err . isJoi ) . to . be . true ( ) ;
559+ } ) ;
560+
561+ it ( 'ignores incorrect simulation object' , async ( ) => {
562+
563+ const dispatch = function ( req , res ) {
564+
565+ res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
566+ res . end ( req . headers . super ) ;
567+ } ;
568+
569+ const res = await Shot . inject ( dispatch , { method : 'get' , url : 'http://example.com:8080/hello' , headers : { Super : 'duper' } , simulate : 'sample string' , validate : false } ) ;
570+ expect ( res . payload ) . to . equal ( 'duper' ) ;
571+ } ) ;
572+
573+ it ( 'errors for an incorrect simulation object values' , async ( ) => {
574+
575+ const err = await expect ( Shot . inject ( ( req , res ) => { } , { url : '/' , simulate : { end : 'wrong input' } } ) ) . to . reject ( ) ;
576+ expect ( err . isJoi ) . to . be . true ( ) ;
577+ } ) ;
540578} ) ;
541579
542580describe ( 'writeHead()' , ( ) => {
@@ -791,44 +829,6 @@ describe('_read()', () => {
791829 expect ( res . payload ) . to . equal ( 'close' ) ;
792830 expect ( events ) . to . equal ( [ 'finish (res)' , 'close (req)' , 'close (res)' ] ) ;
793831 } ) ;
794-
795- it ( 'errors for invalid input options' , async ( ) => {
796-
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 : / ) ;
801- } ) ;
802-
803- it ( 'errors for missing url' , async ( ) => {
804-
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 : / ) ;
806- expect ( err . isJoi ) . to . be . true ( ) ;
807- } ) ;
808-
809- it ( 'errors for an incorrect simulation object' , async ( ) => {
810-
811- const err = await expect ( Shot . inject ( ( req , res ) => { } , { url : '/' , simulate : 'sample string' } ) ) . to . reject ( ) ;
812- expect ( err . isJoi ) . to . be . true ( ) ;
813- } ) ;
814-
815- it ( 'ignores incorrect simulation object' , async ( ) => {
816-
817- const dispatch = function ( req , res ) {
818-
819- res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
820- res . end ( req . headers . super ) ;
821- } ;
822-
823- const res = await Shot . inject ( dispatch , { method : 'get' , url : 'http://example.com:8080/hello' , headers : { Super : 'duper' } , simulate : 'sample string' , validate : false } ) ;
824- expect ( res . payload ) . to . equal ( 'duper' ) ;
825- } ) ;
826-
827- it ( 'errors for an incorrect simulation object values' , async ( ) => {
828-
829- const err = await expect ( Shot . inject ( ( req , res ) => { } , { url : '/' , simulate : { end : 'wrong input' } } ) ) . to . reject ( ) ;
830- expect ( err . isJoi ) . to . be . true ( ) ;
831- } ) ;
832832} ) ;
833833
834834
0 commit comments