@@ -2,7 +2,7 @@ import got from 'got';
2
2
import { URLSearchParams } from 'url' ;
3
3
4
4
import { createFetch } from '../lib/fetch' ;
5
- import { Interceptor , intercept , assert200 , url } from './util' ;
5
+ import { Interceptor , intercept , assert200 , url , ORIGIN } from './util' ;
6
6
7
7
describe ( 'fetch request' , ( ) => {
8
8
let interceptor : Interceptor ;
@@ -37,6 +37,18 @@ describe('fetch request', () => {
37
37
const fetch = createFetch ( got ) ;
38
38
await assert200 ( fetch ( url ( '/foo' ) ) ) ;
39
39
} ) ;
40
+
41
+ it ( 'allows prefixUrl' , async ( ) => {
42
+ expect . assertions ( 1 ) ;
43
+ interceptor . intercept ( '/foo' , 'get' ) . reply ( 200 ) ;
44
+
45
+ const prefixedClient = got . extend ( {
46
+ prefixUrl : ORIGIN
47
+ } )
48
+
49
+ const fetch = createFetch ( prefixedClient ) ;
50
+ await assert200 ( fetch ( '/foo' ) ) ;
51
+ } ) ;
40
52
} ) ;
41
53
42
54
describe ( 'querystring' , ( ) => {
@@ -48,13 +60,27 @@ describe('fetch request', () => {
48
60
await assert200 ( fetch ( url ( '/' , { foo : '123' , bar : '456' } ) ) ) ;
49
61
} ) ;
50
62
51
- it ( 'merges query string parameters' , async ( ) => {
52
- expect . assertions ( 1 ) ;
53
- interceptor . intercept ( '/' , 'get' ) . query ( { foo : '123' , bar : '456' } ) . reply ( 200 ) ;
63
+ } ) ;
54
64
55
- const fetch = createFetch ( got . extend ( { searchParams : { bar : '456' } } ) ) ;
56
- await assert200 ( fetch ( url ( '/' , { foo : '123' } ) ) ) ;
57
- } ) ;
65
+ it ( 'merges query string parameters' , async ( ) => {
66
+ expect . assertions ( 1 ) ;
67
+ interceptor . intercept ( '/' , 'get' ) . query ( { foo : '123' , bar : '456' } ) . reply ( 200 ) ;
68
+
69
+ const fetch = createFetch ( got . extend ( { searchParams : { bar : '456' } } ) ) ;
70
+ await assert200 ( fetch ( url ( '/' , { foo : '123' } ) ) ) ;
71
+ } ) ;
72
+
73
+ it ( 'merges query string parameters with prefixUrl' , async ( ) => {
74
+ expect . assertions ( 1 ) ;
75
+ interceptor . intercept ( '/foo' , 'get' ) . query ( { foo : '123' , bar : '456' } ) . reply ( 200 ) ;
76
+
77
+ const prefixedClient = got . extend ( {
78
+ prefixUrl : ORIGIN ,
79
+ searchParams : { bar : '456' }
80
+ } )
81
+
82
+ const fetch = createFetch ( prefixedClient ) ;
83
+ await assert200 ( fetch ( '/foo?foo=123' ) ) ;
58
84
} ) ;
59
85
60
86
describe ( 'headers' , ( ) => {
@@ -175,7 +201,7 @@ describe('fetch request', () => {
175
201
176
202
} ) ;
177
203
178
- it . only ( "sends own content-type header" , async ( ) => {
204
+ it ( "sends own content-type header" , async ( ) => {
179
205
expect . assertions ( 1 ) ;
180
206
181
207
// as set by the client
0 commit comments