@@ -44,7 +44,7 @@ describe('perform', () => {
44
44
} )
45
45
} )
46
46
47
- test ( 'turbo stream request automatically calls renderTurboStream' , async ( ) => {
47
+ test ( 'turbo stream request automatically calls renderTurboStream when status is ok ' , async ( ) => {
48
48
const mockResponse = new Response ( '' , { status : 200 , headers : { 'Content-Type' : 'text/vnd.turbo-stream.html' } } )
49
49
window . fetch = jest . fn ( ) . mockResolvedValue ( mockResponse )
50
50
jest . spyOn ( FetchResponse . prototype , "ok" , "get" ) . mockReturnValue ( true )
@@ -55,6 +55,21 @@ describe('perform', () => {
55
55
await testRequest . perform ( )
56
56
57
57
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 ( ) ;
58
73
} )
59
74
} )
60
75
0 commit comments