1
- /**
2
- * @vitest -environment node
3
- */
1
+ // @vitest -environment node
4
2
import { http } from './http'
5
3
import { getResponse } from './getResponse'
6
4
7
5
it ( 'returns undefined given empty headers array' , async ( ) => {
8
- expect (
9
- await getResponse ( [ ] , new Request ( 'http://localhost/' ) ) ,
10
- ) . toBeUndefined ( )
6
+ await expect (
7
+ getResponse ( [ ] , new Request ( 'http://localhost/' ) ) ,
8
+ ) . resolves . toBeUndefined ( )
11
9
} )
12
10
13
11
it ( 'returns undefined given no matching handlers' , async ( ) => {
14
- expect (
15
- await getResponse (
12
+ await expect (
13
+ getResponse (
16
14
[ http . get ( '/product' , ( ) => void 0 ) ] ,
17
15
new Request ( 'http://localhost/user' ) ,
18
16
) ,
19
- ) . toBeUndefined ( )
17
+ ) . resolves . toBeUndefined ( )
20
18
} )
21
19
22
20
it ( 'returns undefined given a matching handler that returned no response' , async ( ) => {
23
- expect (
24
- await getResponse (
21
+ await expect (
22
+ getResponse (
25
23
[ http . get ( '*/user' , ( ) => void 0 ) ] ,
26
24
new Request ( 'http://localhost/user' ) ,
27
25
) ,
28
- ) . toBeUndefined ( )
26
+ ) . resolves . toBeUndefined ( )
29
27
} )
30
28
31
29
it ( 'returns undefined given a matching handler that returned explicit undefined' , async ( ) => {
32
- expect (
33
- await getResponse (
30
+ await expect (
31
+ getResponse (
34
32
[ http . get ( '*/user' , ( ) => undefined ) ] ,
35
33
new Request ( 'http://localhost/user' ) ,
36
34
) ,
37
- ) . toBeUndefined ( )
35
+ ) . resolves . toBeUndefined ( )
38
36
} )
39
37
40
38
it ( 'returns the response returned from a matching handler' , async ( ) => {
@@ -45,7 +43,7 @@ it('returns the response returned from a matching handler', async () => {
45
43
46
44
expect ( response ?. status ) . toBe ( 200 )
47
45
expect ( response ?. headers . get ( 'Content-Type' ) ) . toBe ( 'application/json' )
48
- expect ( await response ?. json ( ) ) . toEqual ( { name : 'John' } )
46
+ await expect ( response ?. json ( ) ) . resolves . toEqual ( { name : 'John' } )
49
47
} )
50
48
51
49
it ( 'returns the response from the first matching handler if multiple match' , async ( ) => {
@@ -59,5 +57,18 @@ it('returns the response from the first matching handler if multiple match', asy
59
57
60
58
expect ( response ?. status ) . toBe ( 200 )
61
59
expect ( response ?. headers . get ( 'Content-Type' ) ) . toBe ( 'application/json' )
62
- expect ( await response ?. json ( ) ) . toEqual ( { name : 'John' } )
60
+ await expect ( response ?. json ( ) ) . resolves . toEqual ( { name : 'John' } )
61
+ } )
62
+
63
+ it ( 'supports custom base url' , async ( ) => {
64
+ const response = await getResponse (
65
+ [ http . get ( '/resource' , ( ) => new Response ( 'hello world' ) ) ] ,
66
+ new Request ( 'https://localhost:3000/resource' ) ,
67
+ {
68
+ baseUrl : 'https://localhost:3000/' ,
69
+ } ,
70
+ )
71
+
72
+ expect ( response ?. status ) . toBe ( 200 )
73
+ await expect ( response ?. text ( ) ) . resolves . toBe ( 'hello world' )
63
74
} )
0 commit comments