This repository was archived by the owner on Nov 23, 2024. It is now read-only.
File tree 2 files changed +22
-0
lines changed 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,9 @@ export function fetchBaseQuery({ baseUrl }: { baseUrl?: string } = {}) {
32
32
body,
33
33
...rest ,
34
34
} ;
35
+
35
36
config . headers = new Headers ( headers ) ;
37
+
36
38
if ( ! config . headers . has ( 'content-type' ) ) {
37
39
config . headers . set ( 'content-type' , 'application/json' ) ;
38
40
}
@@ -42,10 +44,12 @@ export function fetchBaseQuery({ baseUrl }: { baseUrl?: string } = {}) {
42
44
}
43
45
44
46
url = joinUrls ( baseUrl , url ) ;
47
+
45
48
if ( params ) {
46
49
const searchParams = new URLSearchParams ( params ) ;
47
50
url += `?${ searchParams . toString ( ) } ` ;
48
51
}
52
+
49
53
const response = await fetch ( url , config ) ;
50
54
51
55
let resultData ;
Original file line number Diff line number Diff line change
1
+ import { joinUrls } from './joinUrls' ;
2
+
3
+ test ( 'correctly joins variations relative urls' , ( ) => {
4
+ expect ( joinUrls ( '/api/' , '/banana' ) ) . toBe ( '/api/banana' ) ;
5
+ expect ( joinUrls ( '/api' , '/banana' ) ) . toBe ( '/api/banana' ) ;
6
+ expect ( joinUrls ( '/api/' , 'banana' ) ) . toBe ( '/api/banana' ) ;
7
+ expect ( joinUrls ( '/api/' , '/banana/' ) ) . toBe ( '/api/banana/' ) ;
8
+ expect ( joinUrls ( '/' , '/banana/' ) ) . toBe ( '/banana/' ) ;
9
+ expect ( joinUrls ( '' , '/banana' ) ) . toBe ( '/banana' ) ;
10
+ expect ( joinUrls ( '' , 'banana' ) ) . toBe ( 'banana' ) ;
11
+ } ) ;
12
+
13
+ test ( 'correctly joins variations of absolute urls' , ( ) => {
14
+ expect ( joinUrls ( 'https://apple.com' , '/api/banana' ) ) . toBe ( 'https://apple.com/api/banana' ) ;
15
+ expect ( joinUrls ( 'https://apple.com' , '/api/banana' ) ) . toBe ( 'https://apple.com/api/banana' ) ;
16
+ expect ( joinUrls ( 'https://apple.com' , 'api/banana' ) ) . toBe ( 'https://apple.com/api/banana' ) ;
17
+ expect ( joinUrls ( 'https://apple.com/' , 'api/banana/' ) ) . toBe ( 'https://apple.com/api/banana/' ) ;
18
+ } ) ;
You can’t perform that action at this time.
0 commit comments