@@ -1341,4 +1341,64 @@ describe('Core htmx Shadow DOM Tests', function() {
13411341 getWorkArea ( ) . innerHTML . should . equal ( 'Clicked!' )
13421342 chai . expect ( getWorkArea ( ) . shadowRoot ) . to . be . a ( 'null' )
13431343 } )
1344+
1345+ it ( 'hx-sync works properly in shadow DOM' , function ( ) {
1346+ var count = 0
1347+ this . server . respondWith ( 'GET' , '/test' , function ( xhr ) {
1348+ xhr . respond ( 200 , { } , 'Click ' + count ++ )
1349+ } )
1350+ make ( '<div hx-sync="this:drop"><button id="b1" hx-get="/test">Initial</button>' +
1351+ ' <button id="b2" hx-get="/test">Initial</button></div>' )
1352+ var b1 = byId ( 'b1' )
1353+ var b2 = byId ( 'b2' )
1354+ b1 . click ( )
1355+ b2 . click ( )
1356+ this . server . respond ( )
1357+ this . server . respond ( )
1358+ b1 . innerHTML . should . equal ( 'Click 0' )
1359+ b2 . innerHTML . should . equal ( 'Initial' )
1360+ } )
1361+
1362+ it ( 'can abort a request programmatically in shadow DOM' , function ( ) {
1363+ var count = 0
1364+ var abortedCount = 0
1365+ this . server . respondWith ( 'GET' , '/test' , function ( xhr ) {
1366+ xhr . respond ( 200 , { } , 'Click ' + count ++ )
1367+ } )
1368+ make ( '<div><button id="b1" hx-get="/test">Initial</button>' +
1369+ ' <button id="b2" hx-get="/test">Initial</button></div>' )
1370+ var b1 = byId ( 'b1' )
1371+ var b2 = byId ( 'b2' )
1372+
1373+ // Listen for abort events to verify they're working
1374+ htmx . on ( b1 , 'htmx:abort' , function ( ) { abortedCount ++ } )
1375+
1376+ b1 . click ( )
1377+ b2 . click ( )
1378+
1379+ htmx . trigger ( b1 , 'htmx:abort' )
1380+
1381+ this . server . respond ( )
1382+ this . server . respond ( )
1383+ b1 . innerHTML . should . equal ( 'Initial' )
1384+ b2 . innerHTML . should . equal ( 'Click 0' )
1385+ abortedCount . should . equal ( 1 )
1386+ } )
1387+
1388+ it ( 'hx-sync abort strategy works in shadow DOM' , function ( ) {
1389+ var count = 0
1390+ this . server . respondWith ( 'GET' , '/test' , function ( xhr ) {
1391+ xhr . respond ( 200 , { } , 'Click ' + count ++ )
1392+ } )
1393+ make ( '<div hx-sync="this"><button hx-sync="closest div:abort" id="b1" hx-get="/test">Initial</button>' +
1394+ ' <button id="b2" hx-get="/test">Initial</button></div>' )
1395+ var b1 = byId ( 'b1' )
1396+ var b2 = byId ( 'b2' )
1397+ b1 . click ( )
1398+ b2 . click ( )
1399+ this . server . respond ( )
1400+ this . server . respond ( )
1401+ b1 . innerHTML . should . equal ( 'Initial' )
1402+ b2 . innerHTML . should . equal ( 'Click 0' )
1403+ } )
13441404} )
0 commit comments