File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,10 @@ export default class Client {
5252 */
5353 buildUrl ( path , params = { } , withLocale = true ) {
5454 const url = new URL ( ( this . locale && withLocale ? `/${ this . locale } ` : '' ) + path , this . baseUrl ) ;
55- url . search = new URLSearchParams ( params ) ;
55+
56+ if ( params ) {
57+ url . search = new URLSearchParams ( params ) ;
58+ }
5659
5760 return url ;
5861 }
Original file line number Diff line number Diff line change @@ -19,15 +19,24 @@ test.describe('Client', () => {
1919 } ) ;
2020
2121 // Feature tests
22- test ( 'should build a correct URL' , async ( ) => {
22+ test ( 'should build a correct URL without params' , async ( ) => {
23+ const url = client . buildUrl ( '/test' ) ;
24+ expect ( url . toString ( ) ) . toBe ( `${ client . baseUrl } /test` ) ;
25+ } ) ;
26+
27+ test ( 'should build a correct URL with params' , async ( ) => {
2328 const url = client . buildUrl ( '/test' , {
2429 foo : 'bar' ,
2530 baz : 'qux' ,
2631 } ) ;
27-
2832 expect ( url . toString ( ) ) . toBe ( `${ client . baseUrl } /test?foo=bar&baz=qux` ) ;
2933 } ) ;
3034
35+ test ( 'should build a correct URL with falsy params' , async ( ) => {
36+ const url = client . buildUrl ( '/test' , false ) ;
37+ expect ( url . toString ( ) ) . toBe ( `${ client . baseUrl } /test` ) ;
38+ } ) ;
39+
3140 test ( 'should transform response' , async ( ) => {
3241 const originalOnResponse = client . onResponse ;
3342 const transformedResponse = {
You can’t perform that action at this time.
0 commit comments