@@ -415,6 +415,44 @@ test('beforeRequest allows modifications', withServer, async (t, server, got) =>
415415 t . is ( body . foo , 'bar' ) ;
416416} ) ;
417417
418+ test ( 'beforeRequest allows overriding searchParams with an object' , withServer , async ( t , server , got ) => {
419+ server . get ( '/' , ( request , response ) => {
420+ response . end ( request . url ) ;
421+ } ) ;
422+
423+ const { body} = await got ( '' , {
424+ searchParams : { old : 'value' } ,
425+ hooks : {
426+ beforeRequest : [
427+ options => {
428+ options . searchParams = { foo : 'bar' } ;
429+ } ,
430+ ] ,
431+ } ,
432+ } ) ;
433+
434+ t . is ( body , '/?foo=bar' ) ;
435+ } ) ;
436+
437+ test ( 'beforeRequest allows overriding searchParams with a string' , withServer , async ( t , server , got ) => {
438+ server . get ( '/' , ( request , response ) => {
439+ response . end ( request . url ) ;
440+ } ) ;
441+
442+ const { body} = await got ( '' , {
443+ searchParams : { old : 'value' } ,
444+ hooks : {
445+ beforeRequest : [
446+ options => {
447+ options . searchParams = 'foo=bar' ;
448+ } ,
449+ ] ,
450+ } ,
451+ } ) ;
452+
453+ t . is ( body , '/?foo=bar' ) ;
454+ } ) ;
455+
418456test ( 'beforeRequest is called with context' , withServer , async ( t , server , got ) => {
419457 server . get ( '/' , echoHeaders ) ;
420458
0 commit comments