Skip to content

Commit

Permalink
chore: [#1615] Continues on implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed Dec 27, 2024
1 parent 20fab0a commit b85782a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/happy-dom/src/html-parser/HTMLParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ export default class HTMLParser {
parentConfig.moveForbiddenDescendant &&
!parentConfig.moveForbiddenDescendant.exclude.includes(lowerTagName)
) {
// We add the element before the first element that is not forbidden.
let before: Node | null = this.currentNode;
while (before) {
if (
Expand All @@ -471,6 +472,7 @@ export default class HTMLParser {
if (before && before.parentNode) {
before.parentNode.insertBefore(this.nextElement, before);
} else {
// If there is no element that is not forbidden, we append the element
before.appendChild(this.nextElement);
}
this.startTagIndex = this.markupRegExp.lastIndex;
Expand Down
17 changes: 10 additions & 7 deletions packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,17 @@ describe('HTMLElement', () => {
element.appendChild(child1);
element.appendChild(child2);

const rootNode = (document.body[PropertySymbol.rootNode] = document.createElement('div'));
const formNode = (document.body[PropertySymbol.formNode] = document.createElement('form'));
const selectNode = (document.body[PropertySymbol.selectNode] =
document.createElement('select'));
const textAreaNode = (document.body[PropertySymbol.textAreaNode] =
document.createElement('textarea'));

document.body.appendChild(element);

const attribute1 = document.createAttribute('test');
attribute1.value = 'test';
element.attributes.setNamedItem(attribute1);

const rootNode = (element[PropertySymbol.rootNode] = document.createElement('div'));
const formNode = (element[PropertySymbol.formNode] = document.createElement('form'));
const selectNode = (element[PropertySymbol.selectNode] = document.createElement('select'));
const textAreaNode = (element[PropertySymbol.textAreaNode] =
document.createElement('textarea'));
const mutationListeners = element[PropertySymbol.mutationListeners];
const isValue = (element[PropertySymbol.isValue] = 'test');

Expand All @@ -592,10 +591,14 @@ describe('HTMLElement', () => {

expect(customElement.childNodes.length).toBe(2);
expect(customElement.childNodes[0]).toBe(child1);
expect(customElement.childNodes[0].parentNode).toBe(customElement);
expect(customElement.childNodes[1]).toBe(child2);
expect(customElement.childNodes[1].parentNode).toBe(customElement);
expect(customElement.children.length).toBe(2);
expect(customElement.children[0]).toBe(child1);
expect(customElement.children[0].parentNode).toBe(customElement);
expect(customElement.children[1]).toBe(child2);
expect(customElement.children[1].parentNode).toBe(customElement);
expect(customElement[PropertySymbol.rootNode] === rootNode).toBe(true);
expect(customElement[PropertySymbol.formNode] === formNode).toBe(true);
expect(customElement[PropertySymbol.selectNode] === selectNode).toBe(true);
Expand Down

0 comments on commit b85782a

Please sign in to comment.