Skip to content

27.0.0 broke multi-level query selecting in vitest/testing-library #3928

@KieranP

Description

@KieranP

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

vitest-jsdom-issue.zip

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions