@@ -18,27 +18,27 @@ afterAll(() => {
1818
1919it ( 'supports throwing a plain Response in a response resolver' , async ( ) => {
2020 server . use (
21- http . get ( 'https ://example.com/ ' , ( ) => {
21+ http . get ( 'http ://localhost/resource ' , ( ) => {
2222 // You can throw a Response instance in a response resolver
2323 // to short-circuit its execution and respond "early".
2424 throw new Response ( 'hello world' )
2525 } ) ,
2626 )
2727
28- const response = await fetch ( 'https ://example.com ' )
28+ const response = await fetch ( 'http ://localhost/resource ' )
2929
3030 expect ( response . status ) . toBe ( 200 )
3131 await expect ( response . text ( ) ) . resolves . toBe ( 'hello world' )
3232} )
3333
3434it ( 'supports throwing an HttpResponse instance in a response resolver' , async ( ) => {
3535 server . use (
36- http . get ( 'https ://example.com/ ' , ( ) => {
36+ http . get ( 'http ://localhost/resource ' , ( ) => {
3737 throw HttpResponse . text ( 'hello world' )
3838 } ) ,
3939 )
4040
41- const response = await fetch ( 'https ://example.com ' )
41+ const response = await fetch ( 'http ://localhost/resource ' )
4242
4343 expect ( response . status ) . toBe ( 200 )
4444 expect ( response . headers . get ( 'Content-Type' ) ) . toBe ( 'text/plain' )
@@ -47,12 +47,12 @@ it('supports throwing an HttpResponse instance in a response resolver', async ()
4747
4848it ( 'supports throwing an error response in a response resolver' , async ( ) => {
4949 server . use (
50- http . get ( 'https ://example.com/ ' , ( ) => {
50+ http . get ( 'http ://localhost/resource ' , ( ) => {
5151 throw HttpResponse . text ( 'not found' , { status : 400 } )
5252 } ) ,
5353 )
5454
55- const response = await fetch ( 'https ://example.com ' )
55+ const response = await fetch ( 'http ://localhost/resource ' )
5656
5757 expect ( response . status ) . toBe ( 400 )
5858 expect ( response . headers . get ( 'Content-Type' ) ) . toBe ( 'text/plain' )
@@ -61,17 +61,19 @@ it('supports throwing an error response in a response resolver', async () => {
6161
6262it ( 'supports throwing a network error in a response resolver' , async ( ) => {
6363 server . use (
64- http . get ( 'https ://example.com/ ' , ( ) => {
64+ http . get ( 'http ://localhost/resource ' , ( ) => {
6565 throw HttpResponse . error ( )
6666 } ) ,
6767 )
6868
69- await expect ( fetch ( 'https://example.com' ) ) . rejects . toThrow ( 'Failed to fetch' )
69+ await expect ( fetch ( 'http://localhost/resource' ) ) . rejects . toThrow (
70+ 'Failed to fetch' ,
71+ )
7072} )
7173
7274it ( 'supports middleware-style responses' , async ( ) => {
7375 server . use (
74- http . get ( 'https ://example.com/ ' , ( { request } ) => {
76+ http . get ( 'http ://localhost/resource ' , ( { request } ) => {
7577 const url = new URL ( request . url )
7678
7779 if ( ! url . searchParams . has ( 'id' ) ) {
@@ -82,25 +84,25 @@ it('supports middleware-style responses', async () => {
8284 } ) ,
8385 )
8486
85- const response = await fetch ( 'https ://example.com/ ?id=1' )
87+ const response = await fetch ( 'http ://localhost/resource ?id=1' )
8688 expect ( response . status ) . toBe ( 200 )
8789 expect ( response . headers . get ( 'Content-Type' ) ) . toBe ( 'text/plain' )
8890 await expect ( response . text ( ) ) . resolves . toBe ( 'ok' )
8991
90- const errorResponse = await fetch ( 'https ://example.com/ ' )
92+ const errorResponse = await fetch ( 'http ://localhost/resource ' )
9193 expect ( errorResponse . status ) . toBe ( 400 )
9294 expect ( errorResponse . headers . get ( 'Content-Type' ) ) . toBe ( 'text/plain' )
9395 await expect ( errorResponse . text ( ) ) . resolves . toBe ( 'must have id' )
9496} )
9597
9698it ( 'coerces non-response errors into 500 error responses' , async ( ) => {
9799 server . use (
98- http . get ( 'https ://example.com/ ' , ( ) => {
100+ http . get ( 'http ://localhost/resource ' , ( ) => {
99101 throw new Error ( 'Custom error' )
100102 } ) ,
101103 )
102104
103- const response = await fetch ( 'https ://example.com ' )
105+ const response = await fetch ( 'http ://localhost/resource ' )
104106
105107 expect ( response . status ) . toBe ( 500 )
106108 expect ( response . statusText ) . toBe ( 'Unhandled Exception' )
0 commit comments