File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,6 +137,10 @@ export default class ElementUtility {
137137 referenceNode : Node | null ,
138138 options ?: { disableAncestorValidation ?: boolean }
139139 ) : Node {
140+ if ( newNode === referenceNode ) {
141+ return newNode ;
142+ }
143+
140144 // NodeUtility.insertBefore() will call appendChild() for the scenario where "referenceNode" is "null" or "undefined"
141145 if ( newNode [ PropertySymbol . nodeType ] === NodeTypeEnum . elementNode && referenceNode ) {
142146 if (
Original file line number Diff line number Diff line change @@ -1247,6 +1247,18 @@ describe('Element', () => {
12471247 const elements = container . querySelectorAll ( 'p' ) ;
12481248 expect ( elements . length ) . toBe ( 1 ) ;
12491249 } ) ;
1250+
1251+ it ( 'Inserts correctly with when adding a children that is already inserted' , ( ) => {
1252+ const container = document . createElement ( 'div' ) ;
1253+ const child = document . createElement ( 'p' ) ;
1254+ child . textContent = 'A' ;
1255+ container . appendChild ( child ) ;
1256+
1257+ container . insertBefore ( child , child ) ;
1258+
1259+ const elements = container . querySelectorAll ( 'p' ) ;
1260+ expect ( elements . length ) . toBe ( 1 ) ;
1261+ } ) ;
12501262 } ) ;
12511263
12521264 describe ( 'get previousElementSibling()' , ( ) => {
You can’t perform that action at this time.
0 commit comments