File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed
Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 11CHANGELOG
22=========
33
4+ Next release
5+ ------------
6+
7+ * Add support ` URL ` instance for ` request ` helper.
8+
49v1.0.8
510------
611
Original file line number Diff line number Diff line change @@ -98,11 +98,15 @@ function parseXhrHeaders(raw: string): Headers {
9898 return headers ;
9999}
100100
101- export function request ( url : string ) : Promise < Response > ;
102- export function request ( url : string , init ?: RequestInit ) : Promise < Response > ;
103- export function request ( url : string , init : UploadRequestInit ) : Promise < Response > ;
101+ export function request ( url : URL | string ) : Promise < Response > ;
102+ export function request ( url : URL | string , init ?: RequestInit ) : Promise < Response > ;
103+ export function request ( url : URL | string , init : UploadRequestInit ) : Promise < Response > ;
104+
105+ export function request ( url : URL | string , init ?: unknown ) : Promise < Response > {
106+ if ( url instanceof URL ) {
107+ url = url . href ;
108+ }
104109
105- export function request ( url : string , init ?: unknown ) : Promise < Response > {
106110 if ( init && isUploadRequestInit ( init ) ) {
107111 return xhrRequest ( url , init ) ;
108112 }
Original file line number Diff line number Diff line change @@ -20,6 +20,13 @@ describe('request', () => {
2020 expect ( response ) . toStrictEqual ( new Response ( null , { status : status } ) ) ;
2121 } ) ;
2222
23+ it ( 'succeeds with URL instance' , async ( ) => {
24+ await request ( new URL ( '/path?k=v' , 'https://foo.local' ) ) ;
25+
26+ expect ( fetchMock ) . toHaveBeenCalledOnce ( ) ;
27+ expect ( fetchMock ) . toHaveBeenCalledWith ( 'https://foo.local/path?k=v' , undefined ) ;
28+ } ) ;
29+
2330 it ( 'succeeds for GET request via fetch with custom options' , async ( ) => {
2431 const resultResponse = new Response ( null , {
2532 status : 200 ,
You can’t perform that action at this time.
0 commit comments