You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
11 |*
12 |* @param message Message.
13 |* @param name Name.
14 |*/
15 | constructor(message, name = null) {
16 | super(message);
^
DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
However, when running this code in a real browser environment, it works as expected. It seems that happy-DOM does not fully support Node.prototype.before() or handles the DOM differently.
The text was updated successfully, but these errors were encountered:
It does appear to be a bug indeed caused by having the wrong parent being used. The parent should be from the element that this is being called on rather than from the child node. It seems like an easy fix. I am not really sure why the child node parent is used as that seems like it would be wrong every time.
/**
public static before(childNode: IChildNode, ...nodes: (string | Node)[]): void {
const parent = <IParentNode>childNode[PropertySymbol.parentNode];
if (!parent) {
return;
}
for (const node of nodes) {
if (node instanceof Node) {
parent.insertBefore(node, childNode);
} else {
parent.insertBefore(
parent[PropertySymbol.ownerDocument].createTextNode(String(node)),
childNode
);
}
}
}
When running the following test:
I encounter this error:
However, when running this code in a real browser environment, it works as expected. It seems that happy-DOM does not fully support
Node.prototype.before()
or handles the DOM differently.The text was updated successfully, but these errors were encountered: