@@ -19,7 +19,9 @@ describe('Core htmx Shadow DOM Tests', function() {
1919 afterEach ( function ( ) {
2020 this . server . restore ( )
2121 clearWorkArea ( )
22- getWorkArea ( ) . shadowRoot . innerHTML = ''
22+ var workArea = getWorkArea ( )
23+ if ( ! workArea . shadowRoot ) workArea . attachShadow ( { mode : 'open' } )
24+ workArea . shadowRoot . innerHTML = ''
2325 } )
2426
2527 // Locally redefine the `byId` and `make` functions to use shadow DOM
@@ -67,6 +69,14 @@ describe('Core htmx Shadow DOM Tests', function() {
6769 }
6870 } )
6971 } )
72+ it ( 'properly retrives shadow root host for extended selector' , function ( ) {
73+ var div = make ( '<div hx-target="host"></div>' )
74+ htmx . defineExtension ( 'test/shadowdom.js' , {
75+ init : function ( api ) {
76+ api . getTarget ( div ) . should . equal ( getWorkArea ( ) )
77+ }
78+ } )
79+ } )
7080
7181 // bootstrap test
7282 it ( 'issues a GET request on click and swaps content' , function ( ) {
@@ -1313,4 +1323,34 @@ describe('Core htmx Shadow DOM Tests', function() {
13131323 window . foo . should . equal ( true )
13141324 delete window . foo
13151325 } )
1326+
1327+ it ( 'can target shadow DOM Host and place content below web component' , function ( ) {
1328+ this . server . respondWith ( 'GET' , '/test' , '<div id="r1">Clicked!</div>' )
1329+ var btn = make ( '<button hx-get="/test" hx-target="host" hx-swap="afterend">Click Me!</button>' )
1330+ btn . click ( )
1331+ this . server . respond ( )
1332+ var r1 = document . getElementById ( 'r1' )
1333+ r1 . innerHTML . should . equal ( 'Clicked!' )
1334+ r1 . remove ( )
1335+ } )
1336+
1337+ it ( 'can target global id outside shadow DOM and place content' , function ( ) {
1338+ this . server . respondWith ( 'GET' , '/test' , '<div id="r2">Clicked!</div>' )
1339+ var btn = make ( '<button hx-get="/test" hx-target="global #work-area" hx-swap="beforebegin">Click Me!</button>' )
1340+ btn . click ( )
1341+ this . server . respond ( )
1342+ var r2 = document . getElementById ( 'r2' )
1343+ r2 . innerHTML . should . equal ( 'Clicked!' )
1344+ r2 . remove ( )
1345+ } )
1346+
1347+ it ( 'can target shadow DOM Host with outerHTML swap and replace it' , function ( ) {
1348+ this . server . respondWith ( 'GET' , '/test' , '<div id="work-area" hx-history-elt>Clicked!</div>' )
1349+ var btn = make ( '<button hx-get="/test" hx-target="host" hx-swap="outerHTML">Click Me!</button>' )
1350+ btn . click ( )
1351+ chai . expect ( getWorkArea ( ) . shadowRoot ) . to . not . be . a ( 'null' )
1352+ this . server . respond ( )
1353+ getWorkArea ( ) . innerHTML . should . equal ( 'Clicked!' )
1354+ chai . expect ( getWorkArea ( ) . shadowRoot ) . to . be . a ( 'null' )
1355+ } )
13161356} )
0 commit comments