@@ -281,3 +281,34 @@ describe('query params are parsed', () => {
281281 expect ( emptyQueryRequest . url ) . toBe ( "localhost/test" )
282282 } )
283283} )
284+
285+
286+ describe ( 'turbostream' , ( ) => {
287+ test ( 'turbo fetch is called for turbo-stream responseKind' , async ( ) => {
288+ const mockResponse = new Response ( "success!" , { status : 200 } )
289+
290+ window . fetch = jest . fn ( ) . mockResolvedValue ( mockResponse )
291+ window . Turbo = { fetch : jest . fn ( ) . mockResolvedValue ( mockResponse ) }
292+
293+ const testRequest = new FetchRequest ( "get" , "localhost" , { responseKind : 'turbo-stream' } )
294+ const testResponse = await testRequest . perform ( )
295+
296+ expect ( window . Turbo . fetch ) . toHaveBeenCalledTimes ( 1 )
297+ expect ( window . fetch ) . toHaveBeenCalledTimes ( 0 )
298+ expect ( testResponse ) . toStrictEqual ( new FetchResponse ( mockResponse ) )
299+ } )
300+
301+ test ( 'turbo fetch is called for other responseKind' , async ( ) => {
302+ const mockResponse = new Response ( "success!" , { status : 200 } )
303+
304+ window . fetch = jest . fn ( ) . mockResolvedValue ( mockResponse )
305+ window . Turbo = { fetch : jest . fn ( ) . mockResolvedValue ( mockResponse ) }
306+
307+ const testRequest = new FetchRequest ( "get" , "localhost" )
308+ const testResponse = await testRequest . perform ( )
309+
310+ expect ( window . Turbo . fetch ) . toHaveBeenCalledTimes ( 0 )
311+ expect ( window . fetch ) . toHaveBeenCalledTimes ( 1 )
312+ expect ( testResponse ) . toStrictEqual ( new FetchResponse ( mockResponse ) )
313+ } )
314+ } )
0 commit comments