Closed marcotas closed 3 months ago
Can you provide a reproduction link?
Hi, I have the same issue caused by this recent fix: https://github.com/capricorn86/happy-dom/pull/1407
I created a repo to reproduce this issue: https://github.com/alk-sdavid/happy-dom-issue (install deps then run npm test
).
It logs the same error as Marco commented:
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.
Same test works with happy-dom@14.8.2, then it starts failing with happy-dom@14.8.3
I didn't have time to dig more, but in my use case it craches when I try to test a Radix select rendered in a Radix dialog which uses a React portal...
It happens also to me using the Dialog component from Radix. It seems that happens because the focus guards functionality.
After some digging I have realized that it performs some radix utilities trigger document.body.insertAdjacentElement('afterbegin', element);
:
insertBefore
is called with a node that the parent already contains.Node.insertBefore
method are the same element.I think this test should pass:
it('Does not insert a children that is already inserted', () => {
const container = document.createElement('div');
const child = document.createElement('p');
child.textContent = 'A';
container.appendChild(child);
container.insertBefore(child, child);
const elements = container.querySelectorAll('p');
expect(elements.length).toBe(1);
});
Describe the bug I'm getting this error inside radix-vue after updating the happy-dom package from
14.7.1
to14.10.1
. It seems to me that it's a change on the most recent version of happy-dom package that is breaking my unit tests.Everything works as expected on the browser. How should I solve this? Any ideas?
Screenshots
Error text:
Device: