@@ -44,7 +44,7 @@ describe('perform', () => {
4444 } )
4545 } )
4646
47- test ( 'turbo stream request automatically calls renderTurboStream' , async ( ) => {
47+ test ( 'turbo stream request automatically calls renderTurboStream when status is ok ' , async ( ) => {
4848 const mockResponse = new Response ( '' , { status : 200 , headers : { 'Content-Type' : 'text/vnd.turbo-stream.html' } } )
4949 window . fetch = jest . fn ( ) . mockResolvedValue ( mockResponse )
5050 jest . spyOn ( FetchResponse . prototype , "ok" , "get" ) . mockReturnValue ( true )
@@ -55,6 +55,21 @@ describe('perform', () => {
5555 await testRequest . perform ( )
5656
5757 expect ( renderSpy ) . toHaveBeenCalledTimes ( 1 )
58+ jest . clearAllMocks ( ) ;
59+ } )
60+
61+ test ( 'turbo stream request automatically calls renderTurboStream when status is unprocessable entity' , async ( ) => {
62+ const mockResponse = new Response ( '' , { status : 422 , headers : { 'Content-Type' : 'text/vnd.turbo-stream.html' } } )
63+ window . fetch = jest . fn ( ) . mockResolvedValue ( mockResponse )
64+ jest . spyOn ( FetchResponse . prototype , "ok" , "get" ) . mockReturnValue ( true )
65+ jest . spyOn ( FetchResponse . prototype , "isTurboStream" , "get" ) . mockReturnValue ( true )
66+ const renderSpy = jest . spyOn ( FetchResponse . prototype , "renderTurboStream" ) . mockImplementation ( )
67+
68+ const testRequest = new FetchRequest ( "get" , "localhost" )
69+ await testRequest . perform ( )
70+
71+ expect ( renderSpy ) . toHaveBeenCalledTimes ( 1 )
72+ jest . clearAllMocks ( ) ;
5873 } )
5974} )
6075
0 commit comments