capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.25k stars 197 forks source link

Node.contains doesn't handle undefined args #1285

Closed rofly closed 6 months ago

rofly commented 6 months ago

Describe the bug

Calling Node.contains with undefined argument raises a TypeError exception.

"TypeError": Cannot read properties of undefined (reading 'Symbol(parentNode)')

To Reproduce

Run the following code snippet

const happyDom = require("happy-dom");

const happyWindow = new happyDom.Window();
const parentElement = happyWindow.document.createElement('div');
const childElement = happyWindow.document.createElement('div');

parentElement.appendChild(childElement);

let nonInitializedElement;

parentElement.contains(nonInitializedElement);

Expected behavior

The same behavior that happens in the browser. Node.contains should return false when it's called with undefined