@@ -210,3 +210,39 @@ test('targeting `_top` will reload the page when redirected back to the same URL
210
210
} )
211
211
}
212
212
)
213
+
214
+ test ( 'targeting `_none` will neither reload the page nor attempt to alter the DOM' ,
215
+ html `< form x-target x-target.302 ="_none " id ="form "
216
+ @ajax:success ="document.getElementById('form').id = 'success' "
217
+ @ajax:missing ="document.getElementById('success').id = 'missing' "
218
+ @ajax:merge ="document.getElementById('success').id = 'merge' "> < button id ="button "> </ button > </ form > ` ,
219
+ ( { intercept, get, wait } ) => {
220
+ intercept ( 'POST' , '/tests' , ( request ) => {
221
+ request . redirect ( '/tests' , 302 )
222
+ } )
223
+ intercept ( 'GET' , '/tests' , {
224
+ statusCode : 200 ,
225
+ body : ''
226
+ } ) . as ( 'response' )
227
+ get ( 'button' ) . click ( )
228
+ wait ( '@response' ) . then ( ( ) => {
229
+ get ( '#button' ) . should ( 'exist' )
230
+ get ( '#success' ) . should ( 'exist' )
231
+ } )
232
+ }
233
+ )
234
+
235
+ test ( 'targeting `_none` for redirects will not prevent non-redirect responses from updating the DOM' ,
236
+ html `< form x-target x-target.302 ="_none " id ="replace "> < button id ="button "> </ button > </ form > ` ,
237
+ ( { intercept, get, wait } ) => {
238
+ intercept ( 'GET' , '/tests' , {
239
+ statusCode : 200 ,
240
+ body : '<div id="replace">Replaced</div>'
241
+ } ) . as ( 'response' )
242
+ get ( 'button' ) . click ( )
243
+ wait ( '@response' ) . then ( ( ) => {
244
+ get ( '#button' ) . should ( 'not.exist' )
245
+ get ( '#replace' ) . should ( 'have.text' , 'Replaced' )
246
+ } )
247
+ }
248
+ )
0 commit comments