-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Node.js version
22.15.1
jsdom version
27.0.0
What is the problem?
As per the issue template, I expect this will be closed, and I wouldn't want to waste your time, but I thought you might want to at least know that upgrading from 26.1.0 to 27.0.0 introduced a major undocumented change/regression that broke tests that rely on nested query selection. It seems that document.querySelector now always operates from root now, so nested calls ignore all previous ones.
Minimal reproduction case
import { JSDOM } from "jsdom";
const dom = new JSDOM(`
<div>
<span>Actions</span>
<ul>
<li>
<a href="/">
<span>Link</span>
</a>
</li>
</ul>
</div>
`);
const document = dom.window.document;
const anchor = document.querySelector("a");
// console.log(anchor); // Uncomment this and it works?!
const span = anchor.querySelector("span");
console.log(span.innerHTML);Outputs "Actions" instead of "Link"
How does similar code behave in browsers?
It scopes queries based on previous selectors
Metadata
Metadata
Assignees
Labels
No labels