Skip to content

Commit

Permalink
chore(snc): fix snc errors in src/mock-doc/node.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduy1407 committed Nov 30, 2024
1 parent 19249c2 commit 8df49b5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/mock-doc/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,13 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
}

insertAdjacentElement(position: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend', elm: MockHTMLElement) {
if (position === 'beforebegin') {
if (position === 'beforebegin' && this.parentNode) {
insertBefore(this.parentNode, elm, this);
} else if (position === 'afterbegin') {
this.prepend(elm);
} else if (position === 'beforeend') {
this.appendChild(elm);
} else if (position === 'afterend') {
} else if (position === 'afterend' && this.parentNode) {
insertBefore(this.parentNode, elm, this.nextSibling);
}
return elm;
Expand All @@ -497,7 +497,9 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
const frag = parseFragmentUtil(this.ownerDocument, html);
if (position === 'beforebegin') {
while (frag.childNodes.length > 0) {
insertBefore(this.parentNode, frag.childNodes[0], this);
if (this.parentNode) {
insertBefore(this.parentNode, frag.childNodes[0], this);
}
}
} else if (position === 'afterbegin') {
while (frag.childNodes.length > 0) {
Expand All @@ -509,20 +511,22 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
}
} else if (position === 'afterend') {
while (frag.childNodes.length > 0) {
insertBefore(this.parentNode, frag.childNodes[frag.childNodes.length - 1], this.nextSibling);
if (this.parentNode) {
insertBefore(this.parentNode, frag.childNodes[frag.childNodes.length - 1], this.nextSibling);
}
}
}
}

insertAdjacentText(position: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend', text: string) {
const elm = this.ownerDocument.createTextNode(text);
if (position === 'beforebegin') {
if (position === 'beforebegin' && this.parentNode) {
insertBefore(this.parentNode, elm, this);
} else if (position === 'afterbegin') {
this.prepend(elm);
} else if (position === 'beforeend') {
this.appendChild(elm);
} else if (position === 'afterend') {
} else if (position === 'afterend' && this.parentNode) {
insertBefore(this.parentNode, elm, this.nextSibling);
}
}
Expand Down Expand Up @@ -1077,7 +1081,7 @@ export function resetElement(elm: MockElement) {
delete elm.__style;
}

function insertBefore(parentNode: MockNode, newNode: MockNode, referenceNode: MockNode) {
function insertBefore(parentNode: MockNode, newNode: MockNode, referenceNode: MockNode | null) {
if (newNode !== referenceNode) {
newNode.remove();
newNode.parentNode = parentNode;
Expand All @@ -1103,7 +1107,7 @@ function insertBefore(parentNode: MockNode, newNode: MockNode, referenceNode: Mo
export class MockHTMLElement extends MockElement {
override __namespaceURI = 'http://www.w3.org/1999/xhtml';

constructor(ownerDocument: any, nodeName: string) {
constructor(ownerDocument: any, nodeName: string | null) {
super(ownerDocument, typeof nodeName === 'string' ? nodeName.toUpperCase() : null);
}

Expand Down

0 comments on commit 8df49b5

Please sign in to comment.