@@ -481,13 +481,13 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
481
481
}
482
482
483
483
insertAdjacentElement ( position : 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' , elm : MockHTMLElement ) {
484
- if ( position === 'beforebegin' ) {
484
+ if ( position === 'beforebegin' && this . parentNode ) {
485
485
insertBefore ( this . parentNode , elm , this ) ;
486
486
} else if ( position === 'afterbegin' ) {
487
487
this . prepend ( elm ) ;
488
488
} else if ( position === 'beforeend' ) {
489
489
this . appendChild ( elm ) ;
490
- } else if ( position === 'afterend' ) {
490
+ } else if ( position === 'afterend' && this . parentNode ) {
491
491
insertBefore ( this . parentNode , elm , this . nextSibling ) ;
492
492
}
493
493
return elm ;
@@ -497,7 +497,9 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
497
497
const frag = parseFragmentUtil ( this . ownerDocument , html ) ;
498
498
if ( position === 'beforebegin' ) {
499
499
while ( frag . childNodes . length > 0 ) {
500
- insertBefore ( this . parentNode , frag . childNodes [ 0 ] , this ) ;
500
+ if ( this . parentNode ) {
501
+ insertBefore ( this . parentNode , frag . childNodes [ 0 ] , this ) ;
502
+ }
501
503
}
502
504
} else if ( position === 'afterbegin' ) {
503
505
while ( frag . childNodes . length > 0 ) {
@@ -509,20 +511,22 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
509
511
}
510
512
} else if ( position === 'afterend' ) {
511
513
while ( frag . childNodes . length > 0 ) {
512
- insertBefore ( this . parentNode , frag . childNodes [ frag . childNodes . length - 1 ] , this . nextSibling ) ;
514
+ if ( this . parentNode ) {
515
+ insertBefore ( this . parentNode , frag . childNodes [ frag . childNodes . length - 1 ] , this . nextSibling ) ;
516
+ }
513
517
}
514
518
}
515
519
}
516
520
517
521
insertAdjacentText ( position : 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' , text : string ) {
518
522
const elm = this . ownerDocument . createTextNode ( text ) ;
519
- if ( position === 'beforebegin' ) {
523
+ if ( position === 'beforebegin' && this . parentNode ) {
520
524
insertBefore ( this . parentNode , elm , this ) ;
521
525
} else if ( position === 'afterbegin' ) {
522
526
this . prepend ( elm ) ;
523
527
} else if ( position === 'beforeend' ) {
524
528
this . appendChild ( elm ) ;
525
- } else if ( position === 'afterend' ) {
529
+ } else if ( position === 'afterend' && this . parentNode ) {
526
530
insertBefore ( this . parentNode , elm , this . nextSibling ) ;
527
531
}
528
532
}
@@ -1077,7 +1081,7 @@ export function resetElement(elm: MockElement) {
1077
1081
delete elm . __style ;
1078
1082
}
1079
1083
1080
- function insertBefore ( parentNode : MockNode , newNode : MockNode , referenceNode : MockNode ) {
1084
+ function insertBefore ( parentNode : MockNode , newNode : MockNode , referenceNode : MockNode | null ) {
1081
1085
if ( newNode !== referenceNode ) {
1082
1086
newNode . remove ( ) ;
1083
1087
newNode . parentNode = parentNode ;
@@ -1103,7 +1107,7 @@ function insertBefore(parentNode: MockNode, newNode: MockNode, referenceNode: Mo
1103
1107
export class MockHTMLElement extends MockElement {
1104
1108
override __namespaceURI = 'http://www.w3.org/1999/xhtml' ;
1105
1109
1106
- constructor ( ownerDocument : any , nodeName : string ) {
1110
+ constructor ( ownerDocument : any , nodeName : string | null ) {
1107
1111
super ( ownerDocument , typeof nodeName === 'string' ? nodeName . toUpperCase ( ) : null ) ;
1108
1112
}
1109
1113
0 commit comments