Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

element.matches() returns incorrect result for nested selector #1472

Closed
ocavue opened this issue Jun 27, 2024 · 0 comments · Fixed by #1473
Closed

element.matches() returns incorrect result for nested selector #1472

ocavue opened this issue Jun 27, 2024 · 0 comments · Fixed by #1473
Labels
bug Something isn't working

Comments

@ocavue
Copy link
Contributor

ocavue commented Jun 27, 2024

Describe the bug

element.matches(".k > .k") returns incorrect result.

To Reproduce
Steps to reproduce the behavior:

Run the following code, or open https://stackblitz.com/edit/stackblitz-starters-dngcid?file=index.mjs,package.json and run node index.mjs.

import * as happyDom from 'happy-dom';

function test(win) {
  let document = win.document;
  document.body.innerHTML = `
    <div>
      <div class="k a">
        <div>
          <div class="k b">
          </div>
        </div>
      </div>
    </div>`;

  const a = document.querySelector('.a');
  const b = document.querySelector('.b');

  const selector = '.k > .k';

  // Expected "k a false", actual "k a false"
  console.log(a?.className, a?.matches(selector));

  // Expected "k b false", actual "k b true"
  console.log(b?.className, b?.matches(selector));
}

test(new happyDom.Window());

Expected behavior

b.matches(selector) should return false, but it returns true.

Device:

  • OS: macOS
  • Browser Chrome
  • Version 14.12.3
@ocavue ocavue added the bug Something isn't working label Jun 27, 2024
capricorn86 added a commit that referenced this issue Aug 28, 2024
…r combinator (e.g. .x > .x) in matches() and closest() (#1473)

* fix: [#1472] Fix child combinator matching in nested element

* chore: [#1472] Improves logic to hopefully be less confusing

---------

Co-authored-by: David Ortner <david@ortner.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant