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

DOMException: The selector ":nth-of-type" is not valid. #1191

Closed
U-Zo opened this issue Jan 8, 2024 · 1 comment · Fixed by #1193
Closed

DOMException: The selector ":nth-of-type" is not valid. #1191

U-Zo opened this issue Jan 8, 2024 · 1 comment · Fixed by #1193
Labels
bug Something isn't working

Comments

@U-Zo
Copy link

U-Zo commented Jan 8, 2024

image

In the case of nested selectors, it is not valid.

e.g.)

p:not(:nth-of-type(1))
@U-Zo U-Zo added the bug Something isn't working label Jan 8, 2024
@gdorsi
Copy link
Contributor

gdorsi commented Jan 8, 2024

Got the same issue!

I've isolated the problem to SELECTOR_REGEXP which doesn't support pseudo selectors as arguments of other pseudo-selectors: https://github.com/capricorn86/happy-dom/blob/master/packages/happy-dom/src/query-selector/SelectorParser.ts#L22

This is a repro test:

it("Has support for nesting pseudo selectors inside pseudo-selectors arguments", () => {
  const div = document.createElement("div");
  const child = document.createElement("div");
  const child2 = document.createElement("div");

  div.appendChild(child);
  div.appendChild(child2);

  expect(div.querySelector(":not(:nth-child(1))")).toBe(child2);
});

gdorsi added a commit to gdorsi/happy-dom that referenced this issue Jan 8, 2024
gdorsi added a commit to gdorsi/happy-dom that referenced this issue Jan 16, 2024
capricorn86 added a commit that referenced this issue Jan 29, 2024
#1191@patch: Support for passing pseudo-selectors as argument of :not.
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.

2 participants