File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -510,7 +510,7 @@ module.exports = class Interceptor {
510510 strFormattingFn = common . percentDecode
511511 }
512512
513- if ( queries instanceof URLSearchParams ) {
513+ if ( queries instanceof URLSearchParams || typeof queries === 'string' ) {
514514 // Normalize the data into the shape that is matched against.
515515 // Duplicate keys are handled by combining the values into an array.
516516 queries = querystring . parse ( queries . toString ( ) )
Original file line number Diff line number Diff line change @@ -19,6 +19,22 @@ describe('query params in path', () => {
1919} )
2020
2121describe ( '`query()`' , ( ) => {
22+ describe ( 'when called with a string' , ( ) => {
23+ it ( 'matches a url encoded query string of the same name=value' , async ( ) => {
24+ const scope = nock ( 'http://example.test' )
25+ . get ( '/' )
26+ . query ( 'foo%5Bbar%5D%3Dhello%20world%21' )
27+ . reply ( )
28+
29+ const { statusCode } = await got (
30+ 'http://example.test/?foo%5Bbar%5D%3Dhello%20world%21' ,
31+ )
32+
33+ expect ( statusCode ) . to . equal ( 200 )
34+ scope . done ( )
35+ } )
36+ } )
37+
2238 describe ( 'when called with an object' , ( ) => {
2339 it ( 'matches a query string of the same name=value' , async ( ) => {
2440 const scope = nock ( 'http://example.test' )
@@ -256,8 +272,8 @@ describe('`query()`', () => {
256272 const interceptor = nock ( 'http://example.test' ) . get ( '/' )
257273
258274 expect ( ( ) => {
259- interceptor . query ( 'foo=bar' )
260- } ) . to . throw ( Error , 'Argument Error: foo=bar ' )
275+ interceptor . query ( 1 )
276+ } ) . to . throw ( Error , 'Argument Error: 1 ' )
261277 } )
262278 } )
263279
You can’t perform that action at this time.
0 commit comments