1- /**
2- * @vitest -environment node
3- */
1+ // @vitest -environment node
42import { http } from './http'
53import { getResponse } from './getResponse'
64
75it ( '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 ( )
119} )
1210
1311it ( 'returns undefined given no matching handlers' , async ( ) => {
14- expect (
15- await getResponse (
12+ await expect (
13+ getResponse (
1614 [ http . get ( '/product' , ( ) => void 0 ) ] ,
1715 new Request ( 'http://localhost/user' ) ,
1816 ) ,
19- ) . toBeUndefined ( )
17+ ) . resolves . toBeUndefined ( )
2018} )
2119
2220it ( 'returns undefined given a matching handler that returned no response' , async ( ) => {
23- expect (
24- await getResponse (
21+ await expect (
22+ getResponse (
2523 [ http . get ( '*/user' , ( ) => void 0 ) ] ,
2624 new Request ( 'http://localhost/user' ) ,
2725 ) ,
28- ) . toBeUndefined ( )
26+ ) . resolves . toBeUndefined ( )
2927} )
3028
3129it ( 'returns undefined given a matching handler that returned explicit undefined' , async ( ) => {
32- expect (
33- await getResponse (
30+ await expect (
31+ getResponse (
3432 [ http . get ( '*/user' , ( ) => undefined ) ] ,
3533 new Request ( 'http://localhost/user' ) ,
3634 ) ,
37- ) . toBeUndefined ( )
35+ ) . resolves . toBeUndefined ( )
3836} )
3937
4038it ( 'returns the response returned from a matching handler' , async ( ) => {
@@ -45,7 +43,7 @@ it('returns the response returned from a matching handler', async () => {
4543
4644 expect ( response ?. status ) . toBe ( 200 )
4745 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' } )
4947} )
5048
5149it ( '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
5957
6058 expect ( response ?. status ) . toBe ( 200 )
6159 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' )
6374} )
0 commit comments