@@ -16,45 +16,45 @@ describe('body accessors', () => {
1616 test ( 'works multiple times' , async ( ) => {
1717 const mockResponse = new Response ( "Mock" , { status : 200 , headers : new Headers ( { 'Content-Type' : 'text/plain' } ) } )
1818 const testResponse = new FetchResponse ( mockResponse )
19-
19+
20+ expect ( await testResponse . text ) . toBe ( "Mock" )
2021 expect ( await testResponse . text ) . toBe ( "Mock" )
21- expect ( await testResponse . text ) . toBe ( "Mock" )
2222 } )
2323 test ( 'work regardless of content-type' , async ( ) => {
2424 const mockResponse = new Response ( "Mock" , { status : 200 , headers : new Headers ( { 'Content-Type' : 'not/text' } ) } )
2525 const testResponse = new FetchResponse ( mockResponse )
26-
27- expect ( await testResponse . text ) . toBe ( "Mock" )
26+
27+ expect ( await testResponse . text ) . toBe ( "Mock" )
2828 } )
2929 } )
3030 describe ( 'html' , ( ) => {
3131 test ( 'works multiple times' , async ( ) => {
3232 const mockResponse = new Response ( "<h1>hi</h1>" , { status : 200 , headers : new Headers ( { 'Content-Type' : 'application/html' } ) } )
3333 const testResponse = new FetchResponse ( mockResponse )
34-
34+
35+ expect ( await testResponse . html ) . toBe ( "<h1>hi</h1>" )
3536 expect ( await testResponse . html ) . toBe ( "<h1>hi</h1>" )
36- expect ( await testResponse . html ) . toBe ( "<h1>hi</h1>" )
3737 } )
3838 test ( 'rejects on invalid content-type' , async ( ) => {
3939 const mockResponse = new Response ( "<h1>hi</h1>" , { status : 200 , headers : new Headers ( { 'Content-Type' : 'text/plain' } ) } )
4040 const testResponse = new FetchResponse ( mockResponse )
41-
41+
4242 expect ( testResponse . html ) . rejects . toBeInstanceOf ( Error )
4343 } )
4444 } )
4545 describe ( 'json' , ( ) => {
4646 test ( 'works multiple times' , async ( ) => {
4747 const mockResponse = new Response ( JSON . stringify ( { json : 'body' } ) , { status : 200 , headers : new Headers ( { 'Content-Type' : 'application/json' } ) } )
4848 const testResponse = new FetchResponse ( mockResponse )
49-
49+
5050 // works mutliple times
5151 expect ( { json : 'body' } ) . toStrictEqual ( await testResponse . json )
5252 expect ( { json : 'body' } ) . toStrictEqual ( await testResponse . json )
5353 } )
5454 test ( 'rejects on invalid content-type' , async ( ) => {
5555 const mockResponse = new Response ( "<h1>hi</h1>" , { status : 200 , headers : new Headers ( { 'Content-Type' : 'text/json' } ) } )
5656 const testResponse = new FetchResponse ( mockResponse )
57-
57+
5858 expect ( testResponse . json ) . rejects . toBeInstanceOf ( Error )
5959 } )
6060 } )
@@ -85,7 +85,7 @@ describe('body accessors', () => {
8585 const warningSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( )
8686
8787 await testResponse . renderTurboStream ( )
88-
88+
8989 expect ( warningSpy ) . toBeCalled ( )
9090 } )
9191 test ( 'calls turbo' , async ( ) => {
@@ -99,10 +99,18 @@ describe('body accessors', () => {
9999 test ( 'rejects on invalid content-type' , async ( ) => {
100100 const mockResponse = new Response ( "<h1>hi</h1>" , { status : 200 , headers : new Headers ( { 'Content-Type' : 'text/plain' } ) } )
101101 const testResponse = new FetchResponse ( mockResponse )
102-
102+
103103 expect ( testResponse . renderTurboStream ( ) ) . rejects . toBeInstanceOf ( Error )
104104 } )
105105 } )
106+ describe ( 'script' , ( ) => {
107+ test ( 'rejects on invalid content-type' , async ( ) => {
108+ const mockResponse = new Response ( "" , { status : 200 , headers : new Headers ( { 'Content-Type' : 'text/plain' } ) } )
109+ const testResponse = new FetchResponse ( mockResponse )
110+
111+ expect ( testResponse . activeScript ( ) ) . rejects . toBeInstanceOf ( Error )
112+ } )
113+ } )
106114} )
107115
108116describe ( 'fetch response helpers' , ( ) => {
@@ -135,46 +143,46 @@ describe('fetch response helpers', () => {
135143 } )
136144} )
137145describe ( 'http-status helpers' , ( ) => {
138-
146+
139147 test ( '200' , ( ) => {
140148 const mockResponse = new Response ( null , { status : 200 } )
141149 const testResponse = new FetchResponse ( mockResponse )
142-
150+
143151 expect ( testResponse . statusCode ) . toBe ( 200 )
144152 expect ( testResponse . ok ) . toBeTruthy ( )
145- expect ( testResponse . redirected ) . toBeFalsy ( )
153+ expect ( testResponse . redirected ) . toBeFalsy ( )
146154 expect ( testResponse . unauthenticated ) . toBeFalsy ( )
147155 expect ( testResponse . unprocessableEntity ) . toBeFalsy ( )
148156 } )
149-
157+
150158 test ( '401' , ( ) => {
151159 const mockResponse = new Response ( null , { status : 401 } )
152160 const testResponse = new FetchResponse ( mockResponse )
153-
161+
154162 expect ( testResponse . statusCode ) . toBe ( 401 )
155163 expect ( testResponse . ok ) . toBeFalsy ( )
156- expect ( testResponse . redirected ) . toBeFalsy ( )
164+ expect ( testResponse . redirected ) . toBeFalsy ( )
157165 expect ( testResponse . unauthenticated ) . toBeTruthy ( )
158166 expect ( testResponse . unprocessableEntity ) . toBeFalsy ( )
159167 } )
160-
168+
161169 test ( '422' , ( ) => {
162170 const mockResponse = new Response ( null , { status : 422 } )
163171 const testResponse = new FetchResponse ( mockResponse )
164-
172+
165173 expect ( testResponse . statusCode ) . toBe ( 422 )
166174 expect ( testResponse . ok ) . toBeFalsy ( )
167- expect ( testResponse . redirected ) . toBeFalsy ( )
175+ expect ( testResponse . redirected ) . toBeFalsy ( )
168176 expect ( testResponse . unauthenticated ) . toBeFalsy ( )
169177 expect ( testResponse . unprocessableEntity ) . toBeTruthy ( )
170178 } )
171-
179+
172180 test ( '302' , ( ) => {
173181 const mockHeaders = new Headers ( { 'Location' : 'https://localhost/login' } )
174182 const mockResponse = new Response ( null , { status : 302 , url : 'https://localhost/login' , headers : mockHeaders } )
175183 jest . spyOn ( mockResponse , 'redirected' , 'get' ) . mockReturnValue ( true )
176184 const testResponse = new FetchResponse ( mockResponse )
177-
185+
178186 expect ( testResponse . statusCode ) . toBe ( 302 )
179187 expect ( testResponse . ok ) . toBeFalsy ( )
180188 expect ( testResponse . redirected ) . toBeTruthy ( )
0 commit comments